test(invariant): add invariant test code (#789)
Some checks are pending
CI / codecov (push) Waiting to run
Release / release (push) Waiting to run

This commit is contained in:
Gromit (전민재) 2024-11-10 15:45:12 +09:00 committed by GitHub
parent c939d97322
commit 087a9827d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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>();
});
});