|
1 | 1 | import { assert, describe, it } from 'vitest' |
2 | 2 |
|
3 | | -import { EthereumJSError, EthereumJSErrorWithoutCode } from '../src/errors.js' |
| 3 | +import { DEFAULT_ERROR_CODE, EthereumJSError, EthereumJSErrorWithoutCode } from '../src/errors.js' |
4 | 4 |
|
5 | | -enum EthereumJSErrorType { |
6 | | - ETHEREUMJS_ERROR = 'ETHEREUMJS_ERROR', |
7 | | - ETHEREUMJS_UNSET_ERROR_CODE = 'ETHEREUMJS_UNSET_ERROR_CODE', |
8 | | -} |
| 5 | +const TEST_ERROR_CODE = 'TEST_ERROR_CODE' |
| 6 | +const TEST_MSG = 'test error message' |
9 | 7 |
|
10 | 8 | describe('EthereumJSError', () => { |
11 | 9 | it('should create an error with a code', () => { |
12 | | - const error = new EthereumJSError({ code: EthereumJSErrorType.ETHEREUMJS_ERROR }, 'test error') |
13 | | - assert.equal(error.type.code, 'ETHEREUMJS_ERROR') |
14 | | - assert.equal(error.message, 'test error') |
| 10 | + const error = new EthereumJSError({ code: TEST_ERROR_CODE }, TEST_MSG) |
| 11 | + assert.equal(error.type.code, TEST_ERROR_CODE) |
| 12 | + assert.equal(error.message, TEST_MSG) |
15 | 13 | const object = error.toObject() |
16 | | - assert.equal(object.type.code, 'ETHEREUMJS_ERROR') |
17 | | - assert.equal(object.message, 'test error') |
| 14 | + assert.equal(object.type.code, TEST_ERROR_CODE) |
| 15 | + assert.equal(object.message, TEST_MSG) |
18 | 16 | }) |
19 | 17 |
|
20 | | - it('should create an error using the unset code', () => { |
21 | | - const error = EthereumJSErrorWithoutCode('test error') |
22 | | - assert.equal(error.type.code, 'ETHEREUMJS_UNSET_ERROR_CODE') |
23 | | - assert.equal(error.message, 'test error') |
| 18 | + it('should create an error using the ethereumjs error without code', () => { |
| 19 | + const error = EthereumJSErrorWithoutCode(TEST_MSG) |
| 20 | + assert.equal(error.type.code, DEFAULT_ERROR_CODE) |
| 21 | + assert.equal(error.message, TEST_MSG) |
24 | 22 | const object = error.toObject() |
25 | | - assert.equal(object.type.code, 'ETHEREUMJS_UNSET_ERROR_CODE') |
26 | | - assert.equal(object.message, 'test error') |
| 23 | + assert.equal(object.type.code, DEFAULT_ERROR_CODE) |
| 24 | + assert.equal(object.message, TEST_MSG) |
27 | 25 | }) |
28 | 26 | }) |
0 commit comments