Skip to content

Commit

Permalink
Resets the spy even if the test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
rdiazv committed Jun 30, 2017
1 parent 95b6198 commit 282286d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions __tests__/Model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('Model', () => {
let collection
let model
let item
let spy

function resolve (attr) {
return () => {
Expand All @@ -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({})
Expand Down Expand Up @@ -143,18 +152,15 @@ 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)
expect(spy.mock.calls[0][1]).toEqual({
name: 'dylan',
album: 'kind of blue'
})

spy.mockReset()
spy.mockRestore()
})
})

Expand All @@ -165,18 +171,15 @@ 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)
expect(spy.mock.calls[0][1]).toEqual({
name: 'dylan',
album: 'kind of blue'
})

spy.mockReset()
spy.mockRestore()
})

describe('if its optimistic (default)', () => {
Expand Down

0 comments on commit 282286d

Please sign in to comment.