diff --git a/__tests__/Model.spec.js b/__tests__/Model.spec.js index 0656043..8c8354e 100644 --- a/__tests__/Model.spec.js +++ b/__tests__/Model.spec.js @@ -27,6 +27,7 @@ describe('Model', () => { let collection let model let item + let spy function resolve (attr) { return () => { @@ -44,6 +45,14 @@ describe('Model', () => { model = collection.at(0) }) + afterEach(() => { + if (spy) { + spy.mockReset() + spy.mockRestore() + spy = null + } + }) + describe('isRequest', () => { it('returns false if there is no request', () => { const newModel = new MyModel({}) @@ -143,8 +152,8 @@ describe('Model', () => { it('sends merged attributes on the request', () => { const adapter = apiClient() - const spy = jest.spyOn(adapter, 'post') + spy = jest.spyOn(adapter, 'post') model.save({ name }) expect(spy).toHaveBeenCalledTimes(1) @@ -152,9 +161,6 @@ describe('Model', () => { name: 'dylan', album: 'kind of blue' }) - - spy.mockReset() - spy.mockRestore() }) }) @@ -165,8 +171,8 @@ describe('Model', () => { it('sends merged attributes on the request', () => { const adapter = apiClient() - const spy = jest.spyOn(adapter, 'post') + spy = jest.spyOn(adapter, 'post') model.save({ name }) expect(spy).toHaveBeenCalledTimes(1) @@ -174,9 +180,6 @@ describe('Model', () => { name: 'dylan', album: 'kind of blue' }) - - spy.mockReset() - spy.mockRestore() }) describe('if its optimistic (default)', () => {