|
| 1 | +import classifyIDBError from '../../../../lib/storage/providers/IDBKeyValProvider/classifyError'; |
| 2 | +import {StorageErrorClass} from '../../../../lib/storage/errors'; |
| 3 | + |
| 4 | +describe('classifyIDBError', () => { |
| 5 | + it.each([ |
| 6 | + // Dead File/Blob in the payload — the platform-specific dialects of "Failed to write blobs". |
| 7 | + [new DOMException('Failed to write blobs (InvalidBlob)', 'DataError'), StorageErrorClass.INVALID_DATA], |
| 8 | + [new DOMException('Failed to write blobs (IOError)', 'DataError'), StorageErrorClass.INVALID_DATA], |
| 9 | + // Non-serializable payload. |
| 10 | + [new TypeError("Failed to execute 'put' on 'IDBObjectStore': something could not be cloned."), StorageErrorClass.INVALID_DATA], |
| 11 | + // Quota. |
| 12 | + [new DOMException('The quota has been exceeded.', 'QuotaExceededError'), StorageErrorClass.CAPACITY], |
| 13 | + // Backing-store corruption. |
| 14 | + [new DOMException('Internal error opening backing store for indexedDB.open.', 'UnknownError'), StorageErrorClass.FATAL], |
| 15 | + // Transient connection failures. |
| 16 | + [new DOMException('Connection to Indexed Database server lost. Refresh the page to try again', 'UnknownError'), StorageErrorClass.TRANSIENT], |
| 17 | + [new DOMException('IDB write transaction aborted without an error', 'AbortError'), StorageErrorClass.TRANSIENT], |
| 18 | + // Anything else stays UNKNOWN. |
| 19 | + [new Error('some brand new failure'), StorageErrorClass.UNKNOWN], |
| 20 | + ])('classifies %s as %s', (error, expectedClass) => { |
| 21 | + expect(classifyIDBError(error)).toBe(expectedClass); |
| 22 | + }); |
| 23 | +}); |
0 commit comments