Skip to content

Commit

Permalink
Clear error after successful request
Browse files Browse the repository at this point in the history
  • Loading branch information
p3drosola committed Apr 5, 2017
1 parent 6354eeb commit e449fa8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
37 changes: 37 additions & 0 deletions __tests__/Collection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ describe('Collection', () => {
}
})

it('clears the error', async () => {
reject()
try {
await collection.fetch()
} catch (e) {}
resolve([])()
await collection.fetch()
expect(collection.error).toBe(null)
})

it('removes the model', async () => {
try {
await collection.create(newItem)
Expand Down Expand Up @@ -163,6 +173,15 @@ describe('Collection', () => {
expect(collection.error.body).toBe(error)
}
})
it('clears the error', async () => {
reject()
try {
await collection.fetch()
} catch (e) {}
resolve([])()
await collection.fetch()
expect(collection.error).toBe(null)
})
})

describe('when it succeeds', () => {
Expand Down Expand Up @@ -211,6 +230,15 @@ describe('Collection', () => {
expect(collection.models.length).toBe(2)
expect(collection.at(1).get('name')).toBe('bob')
})

it('clears the error', async () => {
try {
await collection.fetch()
} catch (e) {}
resolve([item, { id: 2, name: 'bob' }])()
await collection.fetch()
expect(collection.error).toBe(null)
})
})
})

Expand Down Expand Up @@ -291,6 +319,15 @@ describe('Collection', () => {
expect(collection.error.body).toBe(error)
}
})

it('clears the error', async () => {
try {
await collection.fetch()
} catch (e) {}
resolve([])()
await collection.fetch()
expect(collection.error).toBe(null)
})
})

describe('when it succeeds', () => {
Expand Down
3 changes: 3 additions & 0 deletions src/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export default class Collection<T: Model> {
this.add([data])
}
this.request = null
this.error = null
})

return data
Expand Down Expand Up @@ -269,6 +270,7 @@ export default class Collection<T: Model> {
runInAction('fetch-done', () => {
this.set(data, options)
this.request = null
this.error = null
})

return data
Expand Down Expand Up @@ -302,6 +304,7 @@ export default class Collection<T: Model> {
}

this.request = null
this.error = null

return response
}
Expand Down

0 comments on commit e449fa8

Please sign in to comment.