Comments (5)
This is interesting. which version are you using? The internal assumption in the code is that within a given scope, skip always takes precedence, and if a field is both skipped and only'd, we assume that the test should not run.
https://github.com/ealush/vest/blob/release/packages/vest/src/hooks/focused/useIsExcluded.ts#L33
from vest.
I'm on 5.0.0-next-20230905-5c95
. Here is a snippet to paste into vest runkit that shows errorCount: 1
on 5.0.2
version:
var vest = require("vest")
const suite = vest.create(() => {
vest.only('field1');
vest.skip('field1');
vest.test('field1', 'Field 1 is invalid', () => {throw 0});
vest.test('field2', 'Field 2 is invalid', () => {throw 0});
});
suite()
from vest.
OK, yeah. You are right. Re-read the whole part of the code that handles it and now it came back to me.
The way it currently works is as you described. When trying to run a test, vest traverses up from that test to the closest focus
(either skip
or only
) declaration, and once found, it stops searching. Basically, if there are conflicting focus blocks, Vest picks the first one that's declared. The way the internal vest tree looks is somewhat like this:
{
type: 'suite',
optional: {},
children: [
{
type: 'focus',
mode: 'only',
},
{
type: 'focus',
mode: 'skip',
},
{
type: 'test',
testFn: () => { },
fieldName: 'username',
message: 'username is required',
},
],
};
Now, this tree can be infinitely nested with group, each, skipWhen, and the other functions. It can also be infinitely dense.
When trying to understand if a given scope is focused, the search can get very expensive (here's the search I'm doing now: https://github.com/ealush/vest/blob/latest/packages/vest/src/hooks/focused/useIsExcluded.ts#L15, the result of this is handed over to the other function I shared previously), so the cheap solution is first-wins, and it should probably be documented.
I am wondering, what would be a use case in which you need both? We might either be able to achieve it in a different way, or find a way to support that within Vest.
from vest.
Oh, and by the way, Vest 5 is officially out since Thursday.
from vest.
Vest picks the first one that's declared
Ok, so skip; only;
is the correct order to make them work together. skip
will be the first to apply to skipped fields and only
will be the first applied to non-skipped fields.
Use case? This is about those disabled fields. When a field is disabled I can do "suite.remove", but when it comes back from being disabled and if I do not want the tests to run but still want it to affect validity I need to rerun the suite with "only" and "skip" for it.
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
- Omit without when 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.