Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wider expect.it use? #330

Open
msiebuhr opened this issue Aug 22, 2016 · 6 comments
Open

Wider expect.it use? #330

msiebuhr opened this issue Aug 22, 2016 · 6 comments
Labels

Comments

@msiebuhr
Copy link
Contributor

As most things 'just work' in unexpected, I tried out

expect(foo, 'to have property', 'bar', expect.it('to be an', Array));

Not surprised, but a little sad it didn't work :)

(And yes, i know expect(foo, 'to satisfy', {foo: expect.it('to be an', Array)}), but I thought the other might be more readable...

@papandreou
Copy link
Member

Good idea. If we consider expect.it a "safe" escape, we could even consider it for to equal.

@papandreou
Copy link
Member

jest's expect implementation has the concept of a "matcher" (very similar to expect.it) that can fix with pretty much any assertion, including toEqual:

expect({apples: 6, bananas: 3}).toEqual({
  apples: expect.toBeWithinRange(1, 10),
  bananas: expect.not.toBeWithinRange(11, 20),
});

(example taken from https://jestjs.io/docs/en/expect#expectextendmatchers)

It seems like a good idea to me.

@alexjeffburke
Copy link
Member

@papandreou just nothing that a full implementation of that is available in jest-unexpected in case we want to crib anything. That said, I guess I'd lean on the side of expect.it being our canonical solution for this. Did I miss a nuance in your suggestion though?

@papandreou
Copy link
Member

Well, I don't think it'd be easy to implement this, especially not if we want it across every assertion. The "good idea" part was mostly a tip of the hat to the idea in general and the nice and intuitive composition it offers.

Years ago we talked about blurring the lines between to satisfy and to equal and decided not to go down that route, but I don't remember if we specifically discussed expect.it at that point.

@sunesimonsen
Copy link
Member

sunesimonsen commented Jan 10, 2019

We already have this functionality with to exhaustively satisfy right?

To have properties asserting against an object is just a left-over from before the to satisfy-times.

@papandreou
Copy link
Member

We already have this functionality with to exhaustively satisfy right?

Yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants