Comments (4)
Hey @alveshelio, thanks for reaching out.
The short answer to your question is yes, what you want done can be achieved pretty easily with inside, it allows you to check that a value is within an array.
enforce("hello").inside(["hello", "world"]);
The thing is that a typescript enum is not an array, but it transpiles down to an object, so it's not useful just like that. You need to get either the keys or the values:
enum Fruits {
APPLE = "apple",
BANANA = "banana",
CANTELOPE = "cantelope"
}
// ...
// If you need the enum by key:
test('fruit', 'fruit is a key of fruits enum', () => {
// data.fruit is a key of ["APPLE", "BANANA", "CANTELOPE"]
enforce(data.fruit).inside(Object.keys(Fruits));
});
// If you need the enum by value:
test('fruit', 'fruit is a value of fruits enum', () => {
// data.fruit is a value of ["apple", "banana", "cantelope"]
enforce(data.fruit).inside(Object.values(Fruits));
});
Maybe it's a good idea to add two new matchers keyOf
and valueOf`, but until then, these two examples should work for you.
from vest.
Hi @ealush,
Thank you very much for getting back. I think inside()
might be enough.
from vest.
Great example, would be nice to have it in the docs re: handling enum/select ! @ealush
from vest.
Thanks @MentalGear, added to the docs will be automatically published with the next patch to vest.
Thank you for keeping an eye out for things like this.
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.