|
1 |
| -import { isSet, notNullable, requiredIsNotNullable, requiredIsSet } from './filter'; |
| 1 | +import { |
| 2 | + isSet, |
| 3 | + notNullable, |
| 4 | + requiredIsNotNullable, |
| 5 | + requiredIsSet, |
| 6 | +} from "./filter"; |
2 | 7 |
|
3 |
| -type T = { readonly key?: string | null | number | boolean }; |
| 8 | +type T = { |
| 9 | + readonly key?: string | null | number | boolean; |
| 10 | + readonly key2?: string | null | number | boolean; |
| 11 | +}; |
4 | 12 |
|
5 |
| -describe('array.filter(requiredIsSet)', () => { |
6 |
| - it('return true if element is set', () => { |
7 |
| - const test_array: readonly T[] = [ |
8 |
| - { key: 'valid' }, |
9 |
| - { key: null }, |
10 |
| - { key: undefined }, |
11 |
| - {}, |
12 |
| - { key: 0 }, |
13 |
| - { key: false }, |
14 |
| - ] as const; |
| 13 | +describe("array.filter(requiredIsSet)", () => { |
| 14 | + it("return true if element is set", () => { |
| 15 | + const test_array: readonly T[] = [ |
| 16 | + { key: "valid", key2: true }, |
| 17 | + { key: null, key2: true }, |
| 18 | + { key: undefined, key2: true }, |
| 19 | + { key2: true }, |
| 20 | + { key: 0, key2: true }, |
| 21 | + { key: false, key2: true }, |
| 22 | + { key: false, key2: true }, |
| 23 | + ] as const; |
15 | 24 |
|
16 |
| - const result = test_array.filter(requiredIsSet('key')); |
| 25 | + const result = test_array.filter(requiredIsSet("key", "key2")); |
17 | 26 |
|
18 |
| - expect(result).toStrictEqual([{ key: 'valid' }, { key: null }, { key: 0 }, { key: false }]); |
19 |
| - }); |
| 27 | + expect(result).toStrictEqual([ |
| 28 | + { key: "valid", key2: true }, |
| 29 | + { key: null, key2: true }, |
| 30 | + { key: 0, key2: true }, |
| 31 | + { key: false, key2: true }, |
| 32 | + { key: false, key2: true }, |
| 33 | + ]); |
| 34 | + }); |
20 | 35 | });
|
21 | 36 |
|
22 |
| -describe('array.filter(requiredIsNotNullable)', () => { |
23 |
| - it('return true if element is set and not null', () => { |
24 |
| - const test_array: readonly T[] = [ |
25 |
| - { key: 'valid' }, |
26 |
| - { key: null }, |
27 |
| - { key: undefined }, |
28 |
| - {}, |
29 |
| - { key: 0 }, |
30 |
| - { key: false }, |
31 |
| - ] as const; |
32 |
| - |
33 |
| - const result = test_array.filter(requiredIsNotNullable('key')); |
34 |
| - |
35 |
| - expect(result).toStrictEqual([{ key: 'valid' }, { key: 0 }, { key: false }]); |
36 |
| - }); |
| 37 | +describe("array.filter(requiredIsNotNullable)", () => { |
| 38 | + it("return true if element is set and not null", () => { |
| 39 | + const test_array: readonly T[] = [ |
| 40 | + { key: "valid", key2: true }, |
| 41 | + { key: null, key2: true }, |
| 42 | + { key: undefined, key2: true }, |
| 43 | + { key2: true }, |
| 44 | + { key: 0, key2: true }, |
| 45 | + { key: false, key2: true }, |
| 46 | + { key: false, key2: true }, |
| 47 | + ] as const; |
| 48 | + |
| 49 | + const result = test_array.filter(requiredIsNotNullable("key")); |
| 50 | + |
| 51 | + expect(result).toStrictEqual([ |
| 52 | + { key: "valid", key2: true }, |
| 53 | + { key: 0, key2: true }, |
| 54 | + { key: false, key2: true }, |
| 55 | + { key: false, key2: true }, |
| 56 | + ]); |
| 57 | + }); |
37 | 58 | });
|
38 | 59 |
|
39 |
| -describe('array.filter(isSet)', () => { |
40 |
| - it('remove undefined elements', () => { |
41 |
| - const testArray = ['valid', null, undefined, 0, false] as const; |
| 60 | +describe("array.filter(isSet)", () => { |
| 61 | + it("remove undefined elements", () => { |
| 62 | + const testArray = ["valid", null, undefined, 0, false] as const; |
42 | 63 |
|
43 |
| - const result = testArray.filter(isSet); |
| 64 | + const result = testArray.filter(isSet); |
44 | 65 |
|
45 |
| - expect(result).toStrictEqual(['valid', null, 0, false]); |
46 |
| - }); |
| 66 | + expect(result).toStrictEqual(["valid", null, 0, false]); |
| 67 | + }); |
47 | 68 | });
|
48 | 69 |
|
49 |
| -describe('array.filter(notNullable)', () => { |
50 |
| - it('remove null and undefined elements', () => { |
51 |
| - const testArray = ['valid', null, undefined, 0, false] as const; |
| 70 | +describe("array.filter(notNullable)", () => { |
| 71 | + it("remove null and undefined elements", () => { |
| 72 | + const testArray = ["valid", null, undefined, 0, false] as const; |
52 | 73 |
|
53 |
| - const result = testArray.filter(notNullable); |
| 74 | + const result = testArray.filter(notNullable); |
54 | 75 |
|
55 |
| - expect(result).toStrictEqual(['valid', 0, false]); |
56 |
| - }); |
| 76 | + expect(result).toStrictEqual(["valid", 0, false]); |
| 77 | + }); |
57 | 78 | });
|
0 commit comments