|
| 1 | +import { should } from 'chai'; |
| 2 | +import { insist } from '../../tools/integrity'; |
| 3 | + |
| 4 | +should(); |
| 5 | + |
| 6 | +describe('integrity', () => { |
| 7 | + it('should throw TypeError when required property is missing', () => { |
| 8 | + (() => insist({}, 'a')).should.throw(TypeError); |
| 9 | + (() => insist({ a: 1 }, 'a', 'b')).should.throw(TypeError); |
| 10 | + }); |
| 11 | + it('should not throw when all required properties are present', () => { |
| 12 | + (() => insist({ a: 1, b: 2 }, 'a', 'b')).should.not.throw(); |
| 13 | + }); |
| 14 | + it('should allow falsy values (0, false, \'\') as property values', () => { |
| 15 | + (() => insist({ a: 0 }, 'a')).should.not.throw(); |
| 16 | + (() => insist({ a: false }, 'a')).should.not.throw(); |
| 17 | + (() => insist({ a: '' }, 'a')).should.not.throw(); |
| 18 | + }); |
| 19 | + it('should throw when object is null or undefined', () => { |
| 20 | + (() => insist(null as unknown as Record<string, unknown>, 'a')).should.throw(); |
| 21 | + (() => insist(undefined as unknown as Record<string, unknown>, 'a')).should.throw(); |
| 22 | + }); |
| 23 | + it('should not throw when no properties are required', () => { |
| 24 | + (() => insist({ a: 0 })).should.not.throw(); |
| 25 | + }); |
| 26 | +}); |
0 commit comments