Comments (11)
@all-contributors please add @krzysztof-jelski for ideas
from earl.
We already have expect.containerWith
for iterables and we still need arrayWith
and objectWith
.
This is tracked in: #48 so I'll close this as a duplicate.
It will be done during the weekend by me but you can contribute it if you want earlier :-> It's a simple matcher and we have already similar ones.
from earl.
Why close this? The issue is about a validator, not a matcher (even though the name matcher is used)
from earl.
Uhh, I thought it's about matchers. Linking to our docs for completeness: https://earljs.dev/docs/introduction/core-concepts
Still, my thinking is that we don't need validators duplicating what can be easily achieved with existing validators + matchers. For example:
expect({a: 1, b: 2, c: 3}).toContainSubset({a: 1, c: 3})
Is the same as:
expect({a: 1, b: 2, c: 3}).toEqual(expect.objectWith({a: 1, c: 3}))
Matchers are in principle more powerful than validators as they can be used in many different contexts (for example in given
of mocks) and they compose well.
I don't have a very strong opinion on this as I already saw with toThrow
that it's not always a good idea to embrace matchers 😆 But if we decide to introduce these validators, their naming should be inlined with matchers to make it clear that it's a shorthand.
I'll reopen to discuss.
from earl.
Personally i believe it is good to have duplication in this particular case. Possibly also with expect.a
we could have expect(x).toBeA
validator.
All in all it comes down to the fact that the code should be the most descriptive, since the tests serve as specification. So it is more descriptive to write expect([1, 2]).toContain(1)
than expect([1, 2]).toEqual(expect.arrayWith(1))
. The second, while more powerful introduces a lot of noise, potentially leading to people thinking functionality like this is missing.
from earl.
Okay I agree that these validators would be handy indeed. Lets start with:
expect(x).toBeA(...)
usesexpect.a
expect(x).toBeContainerWith
usesexpect.containerWith
expect(x).toBeArrayWith
usesexpect.arrayWith
expect(x).toBeObjectWith
usesexpect.objectWith
Note: I renamed toContainSubset
proposed by @krzysztof-jelski to something that goes well with the names that we picked for matchers.
Let me know if you have any naming suggestions.
from earl.
Yes, the naming looks perfect 👌
from earl.
Hmm perhaps grammar-wise we should add an indefinite article in each one, as in:
expect(x).toBeAnObjectWith
from earl.
Yeah, I wondered about this too. I will check how other libs go about it, after all, we don't have expect.a.objectWith()
🤷
from earl.
@sz-piotr do you have any opinions on naming here?
from earl.
I'd prefer something grammatically correct. So definitely toBeAContainerWith
and toBeAnArrayWith
over toBeContainerWith
and toBeArrayWith
. I'd also propose renaming toBeAContainerWith
to toContain
from earl.
Related Issues (20)
- Improve mocks error message
- Mock's `executes` wrong signature HOT 1
- Knex object cannot be correctly formatted HOT 1
- `toBeAnArrayWith` error message HOT 1
- Rethink ts-essentials dependency and typescript peer dependency HOT 1
- Current plan for validators in 0.3.x HOT 10
- Use bundler like tsup HOT 2
- ESM does not work HOT 2
- No README on npm despite README.md included in package HOT 1
- "Step by step guide" link results in a 404
- expect.subset() not type-safe HOT 1
- expect.toInclude with expect.subset() does not generate helpful error texts
- Documentation website is down HOT 4
- Feature Request: Custom messages
- Feature request: toThrow() / toBeRejected() should return the objects thrown / rejected with
- Possible bug: mockFn().reset() should also reset calls
- Feature request: reset function for MockObjects
- Bug: Assertions on HTMLElements make earl hang
- Possible performance improvement: Generate messages only if assertions fail HOT 2
- Support node built-in test runner HOT 1
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 earl.