Comments (3)
Hey @zeekrey, thanks for reaching out!
Yes, isEmpty
and isNotEmpty
indeed only perform very specific tasks. https://github.com/ealush/vest/blob/latest/packages/n4s/src/rules/isEmpty/index.js, which is not very suitable for checking a date object.
The "empty" Date object that you showed in your code snipped is not empty, since new Date()
defaults to the current time:
new Date().valueOf()
// -> 1596463051635
I believe that what you are looking for is a Date-Object-validity validation rule:
new Date('rr')
// -> Invalid Date
new Date('NaN')
// -> Invalid Date
Which can basically be done with isNaN()
:
isNaN(new Date('x'))
// -> true
isNaN(new Date())
// -> false
Which is an actually good rule to have in Vest. I will add it to the next minor version (2.1).
But in the meantime, you can do either of the following:
// dateObject = new Date('zzz');
test('date', 'Just testing a date object.', () => {
return isNaN(dateObject); // Vest treats `false` as test failure
});
// See https://ealush.com/vest/#/./test?id=explicitly-returning-false for more info
Or, if you want to explicitly use enforce, you can extend enforce to add it locally:
enforce.extend({
isNaN: (value) => isNaN(value)
});
// dateObject = new Date('zzz');
test('date', 'Just testing a date object.', () => {
enforce(dateObject).isNaN();
});
from vest.
Awesome! Thanks for the detailed answer. 😇 I'll go with:
enforce.extend({
isNaN: (value) => isNaN(value)
});// dateObject = new Date('zzz');
test('date', 'Just testing a date object.', () => {
enforce(dateObject).isNaN();
});
from vest.
Glad I was able to help 😀
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
- `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.