Skip to content

Commit bf5545f

Browse files
committed
test(core): type-guards covered with tests
1 parent 550ae64 commit bf5545f

File tree

2 files changed

+51
-27
lines changed

2 files changed

+51
-27
lines changed

packages/core/tests/modules/sanitizer.test.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,6 @@ import { describe, expect, it } from 'vitest';
22
import { Sanitizer } from '../../src';
33

44
describe('Sanitizer', () => {
5-
describe('isObject', () => {
6-
it('should return true for a plain object', () => {
7-
expect(Sanitizer.isObject({})).toBe(true);
8-
});
9-
10-
it('should return false for an array', () => {
11-
expect(Sanitizer.isObject([])).toBe(false);
12-
});
13-
14-
it('should return false for a string', () => {
15-
expect(Sanitizer.isObject('x')).toBe(false);
16-
});
17-
18-
it('should return false for a boolean', () => {
19-
expect(Sanitizer.isObject(true)).toBe(false);
20-
});
21-
22-
it('should return false for null', () => {
23-
expect(Sanitizer.isObject(null)).toBe(false);
24-
});
25-
26-
it('should return false for undefined', () => {
27-
expect(Sanitizer.isObject(undefined)).toBe(false);
28-
});
29-
});
30-
315
describe('sanitize', () => {
326
it('should pass through strings within the length limit', () => {
337
expect(Sanitizer.sanitize('hello')).toBe('hello');

packages/core/tests/utils/type-guards.test.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { isPlainObject } from '../../src';
2+
import { isArray, isClassInstance, isClassPrototype, isPlainObject, isString } from '../../src';
33

44
class Foo {}
55
const fooInstance = new Foo();
@@ -16,3 +16,53 @@ describe('isPlainObject', () => {
1616
it('should return false for class prototype', () => expect(isPlainObject(Foo)).toBe(false));
1717
it('should return false for class instance', () => expect(isPlainObject(fooInstance)).toBe(false));
1818
});
19+
20+
describe('isArray', () => {
21+
it('should return true for empty array', () => expect(isArray([])).toBe(true));
22+
it('should return true for non-empty array', () => expect(isArray([1, 2, 3])).toBe(true));
23+
it('should return false for plain object', () => expect(isArray({})).toBe(false));
24+
it('should return false for string', () => expect(isArray('hello')).toBe(false));
25+
it('should return false for number', () => expect(isArray(42)).toBe(false));
26+
it('should return false for boolean', () => expect(isArray(true)).toBe(false));
27+
it('should return false for null', () => expect(isArray(null)).toBe(false));
28+
it('should return false for undefined', () => expect(isArray(undefined)).toBe(false));
29+
it('should return false for class prototype', () => expect(isArray(Foo)).toBe(false));
30+
it('should return false for class instance', () => expect(isArray(fooInstance)).toBe(false));
31+
});
32+
33+
describe('isClassPrototype', () => {
34+
it('should return true for class prototype', () => expect(isClassPrototype(Foo)).toBe(true));
35+
it('should return false for class instance', () => expect(isClassPrototype(fooInstance)).toBe(false));
36+
it('should return false for plain object', () => expect(isClassPrototype({})).toBe(false));
37+
it('should return false for array', () => expect(isClassPrototype([])).toBe(false));
38+
it('should return false for string', () => expect(isClassPrototype('foo')).toBe(false));
39+
it('should return false for number', () => expect(isClassPrototype(42)).toBe(false));
40+
it('should return false for boolean', () => expect(isClassPrototype(true)).toBe(false));
41+
it('should return false for null', () => expect(isClassPrototype(null)).toBe(false));
42+
it('should return false for undefined', () => expect(isClassPrototype(undefined)).toBe(false));
43+
});
44+
45+
describe('isClassInstance', () => {
46+
it('should return true for class instance', () => expect(isClassInstance(fooInstance)).toBe(true));
47+
it('should return false for class prototype', () => expect(isClassInstance(Foo)).toBe(false));
48+
it('should return false for plain object', () => expect(isClassInstance({})).toBe(false));
49+
it('should return false for array', () => expect(isClassInstance([])).toBe(false));
50+
it('should return false for string', () => expect(isClassInstance('foo')).toBe(false));
51+
it('should return false for number', () => expect(isClassInstance(42)).toBe(false));
52+
it('should return false for boolean', () => expect(isClassInstance(true)).toBe(false));
53+
it('should return false for null', () => expect(isClassInstance(null)).toBe(false));
54+
it('should return false for undefined', () => expect(isClassInstance(undefined)).toBe(false));
55+
});
56+
57+
describe('isString', () => {
58+
it('should return true for string', () => expect(isString('hello')).toBe(true));
59+
it('should return true for empty string', () => expect(isString('')).toBe(true));
60+
it('should return false for plain object', () => expect(isString({})).toBe(false));
61+
it('should return false for array', () => expect(isString([])).toBe(false));
62+
it('should return false for number', () => expect(isString(42)).toBe(false));
63+
it('should return false for boolean', () => expect(isString(true)).toBe(false));
64+
it('should return false for null', () => expect(isString(null)).toBe(false));
65+
it('should return false for undefined', () => expect(isString(undefined)).toBe(false));
66+
it('should return false for class prototype', () => expect(isString(Foo)).toBe(false));
67+
it('should return false for class instance', () => expect(isString(fooInstance)).toBe(false));
68+
});

0 commit comments

Comments
 (0)