ealush / vest

Vest ✅ Declarative validations framework
https://vestjs.dev/
MIT License
2.57k stars 85 forks source link

Eager mode does not work in a group/omitWhen/skipWhen #1132

Closed TG-Modality closed 10 months ago

TG-Modality commented 11 months ago

I was trying the eager mode when I noticed that the eager mode was not working in omitWhen.

The scenario I have is a field that has multiple tests that should be tested based on a condition:

omitWhen(exists, () => {
    test('name', 'Error', () => {
        enforce(data.code).isNotEmpty();
    });

    test('name', 'Error', () => {
        enforce(data.code).lengthEquals(2);
    });

    test('name', 'Error', async () =>
        await callToBackend(data.name)
    );
});

The second and the last tests always triggers, even when the first test is failing.

When tests are outside the omitWhen, the call to backend only triggers when the first 2 tests are successful.

ealush commented 11 months ago

@TG-Modality Thank you for reporting this. I tested your scenario and can confirm that this indeed does not work as expected.

I will work on a fix during the weekend.

TG-Modality commented 11 months ago

@ealush Thank you for your quick response.

ealush commented 10 months ago

Hey @TG-Modality. Sorry for taking the time. It took me a while to debug the issue. It was deep inside the core, regarding how nested scopes are being created.

Now that I have the full grasp of the problem, I'll run several tests and release an update within a few days.

ealush commented 10 months ago

@TG-Modality should be fixed in 5.2.7. Please let me know if everything works as expected

TG-Modality commented 10 months ago

@ealush Thank you very much. The eager mode is working in omitWhen and skipWhen.