mirror of
https://github.com/toss/es-toolkit.git
synced 2024-11-24 11:45:26 +03:00
test(invariant): add invariant test code (#789)
This commit is contained in:
parent
c939d97322
commit
087a9827d4
@ -1,4 +1,4 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, expectTypeOf, it } from 'vitest';
|
||||
import { invariant } from './invariant';
|
||||
|
||||
describe('invariant', () => {
|
||||
@ -30,4 +30,14 @@ describe('invariant', () => {
|
||||
const number = -1;
|
||||
expect(() => invariant(number > 0, 'Number must be positive')).toThrow('Number must be positive');
|
||||
});
|
||||
|
||||
it('should assert non-null value and treat it as string', () => {
|
||||
const value = 'es-toolkit' as string | null;
|
||||
|
||||
invariant(value !== null, 'Value should not be null');
|
||||
|
||||
// Narrow the type.
|
||||
expect(value.length).toBe(10);
|
||||
expectTypeOf(value).toEqualTypeOf<string>();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user