ts-mockery
ts-mockery copied to clipboard
feat: Reset mock extensions
Currently, using Mock.extend will mutate the thing being extended. eg:
foo.ts
export const FOO = {
bar: 'bar';
};
example.test.ts
import { FOO } from './foo';
describe('mutations', () => {
it('can mock FOO.bar', () => {
Mock.extend(FOO).with({bar: 'fake bar'});
expect(FOO.bar).toBe('fake bar');
});
it('bleeds mock data across tests!!', () => {
// This will FAIL if tests are run in definition-order because
// FOO.bar still equals the mock!
expect(FOO.bar).toBe('bar');
});
This change will auto-reset mock extensions to their original values in an automatic afterEach
.
Thoughts
Should we make this configurable? As it is, this change could cause breakages in projects that "depend" on data-bleed across tests.