unexpected icon indicating copy to clipboard operation
unexpected copied to clipboard

Wider expect.it use?

Open msiebuhr opened this issue 9 years ago • 6 comments

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...

msiebuhr avatar Aug 22 '16 09:08 msiebuhr

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

papandreou avatar Aug 22 '16 14:08 papandreou

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.

papandreou avatar Jan 09 '19 21:01 papandreou

@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?

alexjeffburke avatar Jan 09 '19 22:01 alexjeffburke

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.

papandreou avatar Jan 09 '19 22:01 papandreou

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.

sunesimonsen avatar Jan 10 '19 06:01 sunesimonsen

We already have this functionality with to exhaustively satisfy right?

Yes!

papandreou avatar Jan 10 '19 08:01 papandreou