Skip to content

Commit

Permalink
test(invariant): add invariant test code
Browse files Browse the repository at this point in the history
  • Loading branch information
ssi02014 committed Nov 9, 2024
1 parent 67ea6bf commit 1a8c087
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/util/invariant.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from 'vitest';
import { describe, expect, expectTypeOf, it } from 'vitest';
import { invariant } from './invariant';

describe('invariant', () => {
Expand Down Expand Up @@ -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>();
});
});

0 comments on commit 1a8c087

Please sign in to comment.