|
| 1 | +import { checkExceptions, WaiterState } from "./waiter"; |
| 2 | + |
| 3 | +describe(checkExceptions.name, () => { |
| 4 | + const reason = "generic reason"; |
| 5 | + |
| 6 | + it(`throw AbortError if state is ${WaiterState.ABORTED}`, () => { |
| 7 | + const result = { state: WaiterState.ABORTED, reason }; |
| 8 | + expect(() => checkExceptions(result)).toThrow({ |
| 9 | + name: "AbortError", |
| 10 | + message: JSON.stringify({ ...result, reason: "Request was aborted" }), |
| 11 | + }); |
| 12 | + }); |
| 13 | + |
| 14 | + it(`throw TimeoutError if state is ${WaiterState.TIMEOUT}`, () => { |
| 15 | + const result = { state: WaiterState.TIMEOUT, reason }; |
| 16 | + expect(() => checkExceptions(result)).toThrow({ |
| 17 | + name: "TimeoutError", |
| 18 | + message: JSON.stringify({ ...result, reason: "Waiter has timed out" }), |
| 19 | + }); |
| 20 | + }); |
| 21 | + |
| 22 | + it(`throw generic Error if state is ${WaiterState.RETRY}`, () => { |
| 23 | + const result = { state: WaiterState.RETRY, reason }; |
| 24 | + expect(() => checkExceptions(result)).toThrow({ |
| 25 | + name: "Error", |
| 26 | + message: JSON.stringify(result), |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + it(`throw generic Error if state is ${WaiterState.FAILURE}`, () => { |
| 31 | + const result = { state: WaiterState.FAILURE, reason }; |
| 32 | + expect(() => checkExceptions(result)).toThrow({ |
| 33 | + name: "Error", |
| 34 | + message: JSON.stringify(result), |
| 35 | + }); |
| 36 | + }); |
| 37 | + |
| 38 | + it(`return result if state is ${WaiterState.SUCCESS}`, () => { |
| 39 | + const result = { state: WaiterState.SUCCESS }; |
| 40 | + expect(checkExceptions(result)).toEqual(result); |
| 41 | + }); |
| 42 | +}); |
0 commit comments