Jest: Alias `.toInclude` to `.toContain`

Created on 3 Oct 2017  路  4Comments  路  Source: facebook/jest

In the expect library, before being moved over to Jest, .toInclude is used to find if the provided param is found inside the provided array. .toInclude then has an alias of .toContain.

I'm unable to find any reference to a discussion as to why this was changed. In the ECMAScript 2016 spec, a native Array has the method '.includes'. In my opinion, .toInclude is a more natural API than .toContain in this regard. (I've also found myself regularly thinking that .contains is the native API because of this inconsistency, haha)

Could .toInclude be aliased? Is there conflicts with this move? Why was this API changed with the transfer to Jest?

Most helpful comment

toContain

All 4 comments

Nope, we aren't planning on aliasing it or changing the API for it. This is coming from jasmine and we intended to maintain compat with that. You can make your own matcher using expect.extend.

What's the equivalent of toInclude in Jest?

toContain

@SavePointSam @Angristan jest-extended#array has additional array matchers which you might find useful :smile:

Was this page helpful?
0 / 5 - 0 ratings