Skip to content

v1.2.0 - Vitest, plus some new matchers

Compare
Choose a tag to compare
@EskiMojo14 EskiMojo14 released this 18 Feb 21:18
· 124 commits to main since this release

This minor release adds Vitest support, and some new matchers.

Vitest

This release adds support for Vitest, by adding an explicit dependency on jest-matcher-utils for utilities provided by Jest but not Vitest.

See the README for the setup guide.

New matchers

expect.typeOf

This asymmetric matcher checks that a given value has a given typeof.

expect(getPost()).toEqual({ title: expect.typeOf("string") })

expect.arrayContainingOnly

This asymmetric matcher checks that a given array only contains values from an expected array.
Values can be duplicate or omitted, but all values present must match.

expect([1, 2]).toEqual(expect.arrayContainingOnly([1, 2, 3])) // passes
expect([1, 2, 3]).toEqual(expect.arrayContainingOnly([1, 2])) // fails

This is different to expect.arrayContaining, which checks that all expected values are present and allows for other values.

expect([1, 2]).toEqual(expect.arrayContaining([1,2,3])) // fails
expect([1, 2, 3]).toEqual(expect.arrayContaining([1, 2])) // passes

expect.objectContainingOnly

This asymmetric matcher checks that a given object only contains matching keys from an expected object.
Keys can be omitted, but keys present must match.

expect({ a: 1 }).toEqual(expect.objectContainingOnly({ a: 1, b: 2 })) // passes
expect({ a: 1, b: 2 }).toEqual(expect.objectContainingOnly({ a: 1 })) // fails

This is different to expect.objectContaining, which checks that all expected keys are present and allows for other keys.

expect({ a: 1 }).toEqual(expect.objectContaining({ a: 1, b: 2 })) // fails
expect({ a: 1, b: 2 }).toEqual(expect.objectContaining({ a: 1 })) // passes

What's Changed

Full Changelog: v1.1.1...v1.2.0