-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for core/errors module. #546
Signed-off-by: Quan Nguyen <[email protected]>
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {describe, expect, it} from '@jest/globals'; | ||
Check notice on line 1 in fullstack-network-manager/test/unit/core/errors.test.mjs Codacy Production / Codacy Static Code Analysisfullstack-network-manager/test/unit/core/errors.test.mjs#L1
|
||
import { | ||
FullstackTestingError, | ||
ResourceNotFoundError, | ||
MissingArgumentError, | ||
IllegalArgumentError, | ||
DataValidationError | ||
} from '../../../src/core/errors.mjs'; | ||
|
||
describe('Errors', () => { | ||
const message = 'errorMessage'; | ||
const cause = 'cause'; | ||
|
||
it('should construct correct FullstackTestingError', () => { | ||
const error = new FullstackTestingError(message, cause); | ||
expect(error).toBeInstanceOf(Error); | ||
expect(error.name).toBe('FullstackTestingError'); | ||
expect(error.message).toBe(message); | ||
expect(error.cause).toBe(cause); | ||
expect(error.meta).toStrictEqual({}) | ||
}) | ||
|
||
it('should construct correct ResourceNotFoundError', () => { | ||
const resource = 'resource'; | ||
const error = new ResourceNotFoundError(message, resource); | ||
expect(error).toBeInstanceOf(FullstackTestingError); | ||
expect(error.name).toBe('ResourceNotFoundError'); | ||
expect(error.message).toBe(message); | ||
expect(error.cause).toStrictEqual({}) | ||
expect(error.meta).toStrictEqual({ resource }); | ||
}) | ||
|
||
it('should construct correct MissingArgumentError', () => { | ||
const error = new MissingArgumentError(message); | ||
expect(error).toBeInstanceOf(FullstackTestingError); | ||
expect(error.name).toBe('MissingArgumentError'); | ||
expect(error.message).toBe(message); | ||
expect(error.cause).toStrictEqual({}) | ||
expect(error.meta).toStrictEqual({}); | ||
}) | ||
|
||
it('should construct correct IllegalArgumentError', () => { | ||
const value = 'invalid argument'; | ||
const error = new IllegalArgumentError(message, value); | ||
expect(error).toBeInstanceOf(FullstackTestingError); | ||
expect(error.name).toBe('IllegalArgumentError'); | ||
expect(error.message).toBe(message); | ||
expect(error.cause).toStrictEqual({}) | ||
expect(error.meta).toStrictEqual({ value }); | ||
}) | ||
|
||
it('should construct correct DataValidationError', () => { | ||
const expected = 'expected'; | ||
const found = 'found'; | ||
const error = new DataValidationError(message, expected, found); | ||
expect(error).toBeInstanceOf(FullstackTestingError); | ||
expect(error.name).toBe('DataValidationError'); | ||
expect(error.message).toBe(message); | ||
expect(error.cause).toStrictEqual({}) | ||
expect(error.meta).toStrictEqual({ expected, found }); | ||
}) | ||
}) |