ealush / vest

Vest ✅ Declarative validations framework

Home Page:https://vestjs.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with OmitWhen executing code when condition is true

hoangtran-97 opened this issue · comments

Linking MR that adds OmitWhen for reference and it does not have the example about my use case.

In my example below, when the condition is true, is randomFunction supposed to be invoked? My understanding was that when the condition is met, everything in omitWhen will be omitted.

omitWhen(condition, () => {
      randomFunction()
      test("testSomething", ()=>{})
})

Hey @hoangtran-97, thank you for this callout. Yes, this is the expected behavior. I should add it to the documentation.

omitWhen does indeed run everything in its scope. The one thing that doesn't run is the test callback. The reason for it is that Vest keeps track of the tests within it and registers them.

If there's a portion of non vest code that you'd like to omit, you can safely wrap it in a condition (note - do not put Vest api functions in a condition, as it would interfere with this internal registration)

Hi @ealush, thank you for the reply 🙏. Hope this can be added to the documentation soon.