Jest extensions
Usage
some-test.js
:
const jestExtensions = jestExtensions
Assertions
toBeCalledTimes(number)
is an alias fortoHaveBeenCalledTimes(number)
toBeCalledOnce()
is an alias fortoHaveBeenCalledTimes(1)
toBeCalledNthWith(index, arg1, arg2, ...)
is equivalent to:
expect(mockedFunction.mock.calls[index][0]).toEqual(arg1)
expect(mockedFunction.mock.calls[index][1]).toEqual(arg2)
// ...
Asymmetric matchers
expect.and(matcher1, matcher2, ...)
- logical AND operator over many matchers.expect.or(matcher1, matcher2, ...)
- logical OR operator over many matchers.expect.toContain(<value>)
- checks that the value is contained in theactual
collection.expect.toHaveLength(<number>)
- checks that theactual
has a .length property and it is set to a certain numeric value.
Utilities
mockModuleClass
gets a new class with all methods mocked, except those specified in arguments. For example:
./src/MyClass.js
:
{ return } async { // asynchronously request external API } async { return await this }
./src/__tests__/MyClass.test.js
:
{ return }