diff --git a/__tests__/Collection.spec.js b/__tests__/Collection.spec.js index 6f1f985..05b7b43 100644 --- a/__tests__/Collection.spec.js +++ b/__tests__/Collection.spec.js @@ -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) @@ -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', () => { @@ -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) + }) }) }) @@ -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', () => { diff --git a/src/Collection.js b/src/Collection.js index 0d29703..7b7d6a9 100644 --- a/src/Collection.js +++ b/src/Collection.js @@ -235,6 +235,7 @@ export default class Collection { this.add([data]) } this.request = null + this.error = null }) return data @@ -269,6 +270,7 @@ export default class Collection { runInAction('fetch-done', () => { this.set(data, options) this.request = null + this.error = null }) return data @@ -302,6 +304,7 @@ export default class Collection { } this.request = null + this.error = null return response }