Comments (5)
I am afraid it might be confusing with the behavior of skip
, which works within the current scope, while optional works on the suite level. Essentially, at any nesting level where you put skip, it only applies to the descendants of that scope. A consumer of vest could mistake omit() to work just like this.
I am wondering if this is more reasonable to create a general-case omit() that would be similar to the way skip currently works.
from vest.
I think that what you're after is optional with custom rules. Optional has two modes - one that only takes the field name. That's the default behavior, and one that takes a boolean/function value that describes whether the field should be omitted.
optional({
username: true // Will be omitted
});
The only difference between this and omitWhen is that optional runs on a second pass, meaning - it runs the field normally, but then excludes it. I can imagine it useful that if the optional condition is set from the get-go and not a function, it will behave the same as your imagined omit. That's especially true for async validations
from vest.
Oh, cool, I saw optional
but it was documented mostly in the context of a value missing (event custom functions were kinda about that) and there was no example with booleans. Seem to be working, thanks.
from vest.
Scratch My latest comment about the difference with what you're after. Just looked at the code, it behaves just as you'd expect. Wrote a few new tests to confirm that.
from vest.
Hm... so why not introduce omit
as an alias for optional
of sorts?
To omit with optional
I would need to reduce an array into an object and then vest will iterate over that object to make SuiteOptionalFields.setOptionalField
(where third argument can be reused for all omitted, as they have no custom logic or need for checks). So it would be both more convenient and more performant to allow passing an array directly.
omit(["asd"])
as optional({"asd": true})
. (Just a thought, not a request.)
from vest.
Related Issues (20)
- Dynamic fields HOT 6
- Vest@5 is ready! Help test it!
- Last next release does not include development builds in dist HOT 4
- Debounce HOT 9
- Pending info in summary HOT 7
- `skip` and `only` on the same level HOT 5
- Subscribe HOT 6
- Migration guide example code - eager -> mode HOT 1
- Problem with OmitWhen executing code when condition is true HOT 2
- Done and empty suite HOT 3
- In SvelteKit, all the asynchronous tests below do not work at all. HOT 1
- Cannot find name 'Predicate'. Did you mean 'Predicates'? HOT 5
- only.group missing HOT 4
- Stateless suite HOT 2
- isDate alway fails HOT 7
- Multiple groups using same tests function HOT 2
- Eager mode does not work in a group/omitWhen/skipWhen HOT 5
- Support for nested suites HOT 2
- isNotEmpty on a numeric field HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vest.