All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Support for
vitest
andjest
ESM mode Spy.setup
to set up the library- Added section about
bun test
in documentation
Spy.mockModule
removedSpy.mockReactComponents
changed first param type- side effects removed:
Spy.setup
needs to be invoked - default configs changed:
enforceOrder
: false -> trueuseGenericReactMocks
: false -> trueuseOwnEquals
: true -> false
Spy.on
,Spy.mock
andSpy.mockReactComponents
are now type safe
For more detailed information please see Migration Guide v4
- Only use generated TS declaration files instead of sources to avoid TS errors in peers.
spy.hasProps
to check for current props.
- Generic React mocks were causing issues due to illegal named properties.
- Support nested
describe
suites when using mocks.
- spy.getLatestCallArgument
- spy.getProps
- Spy.configure: New configuration option
useGenericReactMocks
.
- Serialization of
window
anddocument
globals ofjest-dom
caused errors.
- Mocking instructions in case of modules exporting properties with only getters.
- CommonJS and Jest runner detection.
- Fix some types after TS update.
- Fix serialization problems of Jest-DOM
HTMLElement
s.
- Fix some types for packages using "strict" TS option with value
false
(not recommended).
- NextJS stopped working because setting
"type": "module"
in ownpackage.json
was overriding the default of the package importer. Hence, the package could only be used as ESM.
- Stricter TS checks and some typing improvements to be included in packages with stricter type checking without causing issues.
- Enforce-Order mode
- Calling
spy.hasCallHistory()
without any arguments will always fail now and refers to usespy.wasNotCalled()
instead if the spy wasn't called.
spy.getAllCallArguments
was returning a wrong value.
flow
supportnode
support for versions lower than 12
- Better TS support and improved auto-import for package users.
new Spy()
->Spy()
(Spy
is no longer a class)
spy.getAllCallArguments
: Provides a little more flexibility when observing call arguments.
- Fixed node module resolution for
Spy.mockModule
Spy.MAPPER
: A nice shortcut variant ofSpy.COMPARE
to test the output of given function depending on some defined input. See here for more details.
-
Spy.mockModule
: Allows you to mock functions on module level. Can replace the usage ofjest.mock
in most situations. One example:// some module with name "my-module.js" export const useMe = (some: string) => 'foo' + some; // testing somewhere else const Mock$MyModule = Spy.mockModule('../my-stuff/my-module', 'useMe'); Mock$MyModule.useMe.returns(42); expect(useMe('test')).toBe(42); Mock$MyModule.useMe.hasCallHistory('test');
-
More detailed error messages.
- Before:
--> foo / different string
- Now:
--> foo / different string ['bar' != 'test']
- Before:
-
Improved UX for
Spy.COMPARE
. You can make assertions that throw instead of returning a boolean indicator. E.g.spy.wasCalledWith(Spy.COMPARE(fn => { expect(fn()).toEqual({ foo: 'bar' }); }));
- Allow to spy on all kind of bound methods (e.g.
window.console.error
which is no instance ofFunction
on JSDom)
- Improved comparison for BigInt and AsyncFunction
- TypeScript support
- Improved types for
Spy.on
andSpy.mock
(this might lead to new type errors)
- improved IDE support by distributing with Rollup
- Snapshot serialization for
jest
snapshots improved
Spy.resetAll
: Calls the reset for all ever instantiated spies.
- The default
afterEach
Test-Suite-Hook now also callsSpy.resetAll
. Therefore created spies should not be able to effect other tests. Since the reset operation is a very cheap operation, this change should not effect the performance of your tests visibly. If any of your tests should break, consider to clean those up, because you should not write conditionally related tests, if it is avoidable.
- Added scopes to mocks: You may use different mocks within different
describe
blocks.
- Migration Guide
Spy.mock
: Create mocks for more control, clarity and developer comfortSpy.initMocks
: Hereby your created mocks are initialized (but you do need to call it manually)- Default Test Suite Hooks:
beforeEach(Spy.initMocks)
andafterEach(Spy.restoreAll)
are applied to each test suite automatically as soon as you use any spies. (very small runtime overhead)
spy.returns
reduces the overhead when resolving promises for e.g. any spied async functionsspy.rejects
reduces the overhead when rejecting promises for e.g. any spied async functions
Spy.COMPARE
to apply custom comparators into arbitrary nested objects to make any equality assumptions.
spy.hasCallHistory
has now a slightly optimized error messages.
spy.hasCallHistory
has now a slightly modified interface.- Improved error visualisation for
spy.hasCallHistory
andspy.wasCalled
- Moved serializer into a separate package
serialize-as-code
- Basic serialization of React JSX
spy.hasCallHistory
as more explicit check on call count and order.
- Treating a property with undefined value the same as a not existing property
- Implemented an own serializer to render any objects
Spy.IGNORE
as flexible replacement for object properties or whole arguments which should be ignored on comparison withspy.wasCalledWith
- Instead of rendering
undefined
just likenull
asnull
it will be rendered as the string "UNDEFINED"
- Comparing Functions returns only equality if functions are identical