|
| 1 | +/** |
| 2 | + * @file Unit Tests - determineSpecificType |
| 3 | + * @module create-node-error/tests/unit/determineSpecificType |
| 4 | + */ |
| 5 | + |
| 6 | +import { inspect } from 'node-inspect-extracted' |
| 7 | +import testSubject from '../determine-specific-type' |
| 8 | + |
| 9 | +describe('unit:determineSpecificType', () => { |
| 10 | + it('should detect bigint', () => { |
| 11 | + // Arrange |
| 12 | + const value: bigint = faker.datatype.bigInt(13) |
| 13 | + const expected: string = `type bigint (${inspect(value, { |
| 14 | + colors: false |
| 15 | + })})` |
| 16 | + |
| 17 | + // Act + Expect |
| 18 | + expect(testSubject(value)).to.equal(expected) |
| 19 | + }) |
| 20 | + |
| 21 | + it('should detect boolean', () => { |
| 22 | + // Arrange |
| 23 | + const value: unknown = faker.datatype.boolean() |
| 24 | + const expected: string = `type boolean (${value})` |
| 25 | + |
| 26 | + // Act + Expect |
| 27 | + expect(testSubject(value)).to.equal(expected) |
| 28 | + }) |
| 29 | + |
| 30 | + it('should detect function', () => { |
| 31 | + // Arrange |
| 32 | + const value: unknown = vi.fn() |
| 33 | + const expected: string = 'function spy' |
| 34 | + |
| 35 | + // Act + Expect |
| 36 | + expect(testSubject(value)).to.equal(expected) |
| 37 | + }) |
| 38 | + |
| 39 | + it('should detect instance object', () => { |
| 40 | + // Arrange |
| 41 | + const value: unknown = faker.datatype.datetime() |
| 42 | + const expected: string = 'an instance of Date' |
| 43 | + |
| 44 | + // Act + Expect |
| 45 | + expect(testSubject(value)).to.equal(expected) |
| 46 | + }) |
| 47 | + |
| 48 | + it('should detect null', () => { |
| 49 | + expect(testSubject(null)).to.equal('null') |
| 50 | + }) |
| 51 | + |
| 52 | + it('should detect number', () => { |
| 53 | + // Arrange |
| 54 | + const value: unknown = faker.datatype.number(13) |
| 55 | + const expected: string = `type number (${value})` |
| 56 | + |
| 57 | + // Act + Expect |
| 58 | + expect(testSubject(value)).to.equal(expected) |
| 59 | + }) |
| 60 | + |
| 61 | + it('should detect string', () => { |
| 62 | + // Arrange |
| 63 | + const value: unknown = faker.datatype.string(30) |
| 64 | + const inspected: string = inspect(value, { colors: false }) |
| 65 | + const expected: string = `type string (${inspected.slice(0, 25)}...)` |
| 66 | + |
| 67 | + // Act + Expect |
| 68 | + expect(testSubject(value)).to.equal(expected) |
| 69 | + }) |
| 70 | + |
| 71 | + it('should detect symbol', () => { |
| 72 | + // Arrange |
| 73 | + const value: unknown = Symbol('kIsNodeError') |
| 74 | + const expected: string = `type symbol (${inspect(value, { |
| 75 | + colors: false |
| 76 | + })})` |
| 77 | + |
| 78 | + // Act + Expect |
| 79 | + expect(testSubject(value)).to.equal(expected) |
| 80 | + }) |
| 81 | + |
| 82 | + it('should detect undefined', () => { |
| 83 | + expect(testSubject(undefined)).to.equal('undefined') |
| 84 | + }) |
| 85 | +}) |
0 commit comments