diff options
author | 2022-06-23 18:10:39 +0200 | |
---|---|---|
committer | 2022-06-23 16:10:39 +0000 | |
commit | 6b2c2b8dfb86245a1747bf7977159f5129461863 (patch) | |
tree | 28944f62a962d8a658262ea902f8554d4419fa9e /src/jsUtils.test.ts | |
parent | chore: featureStore and GlobalErrorStore JS => TS (diff) | |
download | ferdium-app-6b2c2b8dfb86245a1747bf7977159f5129461863.tar.gz ferdium-app-6b2c2b8dfb86245a1747bf7977159f5129461863.tar.zst ferdium-app-6b2c2b8dfb86245a1747bf7977159f5129461863.zip |
chore: servicesStore + models into typescript (#344)
Diffstat (limited to 'src/jsUtils.test.ts')
-rw-r--r-- | src/jsUtils.test.ts | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/jsUtils.test.ts b/src/jsUtils.test.ts index 651caee5f..34cd8f098 100644 --- a/src/jsUtils.test.ts +++ b/src/jsUtils.test.ts | |||
@@ -18,36 +18,53 @@ describe('jsUtils', () => { | |||
18 | }); | 18 | }); |
19 | }); | 19 | }); |
20 | 20 | ||
21 | describe('ifUndefinedBoolean', () => { | 21 | describe('ifUndefined<string>', () => { |
22 | it('returns the default value for undefined input', () => { | 22 | it('returns the default value for undefined input', () => { |
23 | const result = jsUtils.ifUndefinedBoolean(undefined, false); | 23 | const result = jsUtils.ifUndefined<string>(undefined, 'abc'); |
24 | expect(result).toEqual('abc'); | ||
25 | }); | ||
26 | |||
27 | it('returns the default value for null input', () => { | ||
28 | const result = jsUtils.ifUndefined<string>(null, 'abc'); | ||
29 | expect(result).toEqual('abc'); | ||
30 | }); | ||
31 | |||
32 | it('returns the non-default input value for regular string input', () => { | ||
33 | const result = jsUtils.ifUndefined<string>('some random string', 'abc'); | ||
34 | expect(result).toEqual('some random string'); | ||
35 | }); | ||
36 | }); | ||
37 | |||
38 | describe('ifUndefined<boolean>', () => { | ||
39 | it('returns the default value for undefined input', () => { | ||
40 | const result = jsUtils.ifUndefined<boolean>(undefined, false); | ||
24 | expect(result).toEqual(false); | 41 | expect(result).toEqual(false); |
25 | }); | 42 | }); |
26 | 43 | ||
27 | it('returns the default value for null input', () => { | 44 | it('returns the default value for null input', () => { |
28 | const result = jsUtils.ifUndefinedBoolean(null, true); | 45 | const result = jsUtils.ifUndefined<boolean>(null, true); |
29 | expect(result).toEqual(true); | 46 | expect(result).toEqual(true); |
30 | }); | 47 | }); |
31 | 48 | ||
32 | it('returns the non-default input value for regular boolean input', () => { | 49 | it('returns the non-default input value for regular boolean input', () => { |
33 | const result = jsUtils.ifUndefinedBoolean(true, false); | 50 | const result = jsUtils.ifUndefined<boolean>(true, false); |
34 | expect(result).toEqual(true); | 51 | expect(result).toEqual(true); |
35 | }); | 52 | }); |
36 | }); | 53 | }); |
37 | 54 | ||
38 | describe('ifUndefinedNumber', () => { | 55 | describe('ifUndefined<number>', () => { |
39 | it('returns the default value for undefined input', () => { | 56 | it('returns the default value for undefined input', () => { |
40 | const result = jsUtils.ifUndefinedNumber(undefined, 123); | 57 | const result = jsUtils.ifUndefined<number>(undefined, 123); |
41 | expect(result).toEqual(123); | 58 | expect(result).toEqual(123); |
42 | }); | 59 | }); |
43 | 60 | ||
44 | it('returns the default value for null input', () => { | 61 | it('returns the default value for null input', () => { |
45 | const result = jsUtils.ifUndefinedNumber(null, 234); | 62 | const result = jsUtils.ifUndefined<number>(null, 234); |
46 | expect(result).toEqual(234); | 63 | expect(result).toEqual(234); |
47 | }); | 64 | }); |
48 | 65 | ||
49 | it('returns the non-default input value for regular Number input', () => { | 66 | it('returns the non-default input value for regular Number input', () => { |
50 | const result = jsUtils.ifUndefinedNumber(1234, 5678); | 67 | const result = jsUtils.ifUndefined<number>(1234, 5678); |
51 | expect(result).toEqual(1234); | 68 | expect(result).toEqual(1234); |
52 | }); | 69 | }); |
53 | }); | 70 | }); |
@@ -70,10 +87,10 @@ describe('jsUtils', () => { | |||
70 | 87 | ||
71 | it('returns the parsed JSON for the string input', () => { | 88 | it('returns the parsed JSON for the string input', () => { |
72 | const result1 = jsUtils.convertToJSON('{"a":"b","c":"d"}'); | 89 | const result1 = jsUtils.convertToJSON('{"a":"b","c":"d"}'); |
73 | expect(result1).toEqual({a: 'b', c: 'd'}); | 90 | expect(result1).toEqual({ a: 'b', c: 'd' }); |
74 | 91 | ||
75 | const result2 = jsUtils.convertToJSON('[{"a":"b"},{"c":"d"}]'); | 92 | const result2 = jsUtils.convertToJSON('[{"a":"b"},{"c":"d"}]'); |
76 | expect(result2).toEqual([{a: 'b'}, {c: 'd'}]); | 93 | expect(result2).toEqual([{ a: 'b' }, { c: 'd' }]); |
77 | }); | 94 | }); |
78 | }); | 95 | }); |
79 | 96 | ||
@@ -89,8 +106,8 @@ describe('jsUtils', () => { | |||
89 | }); | 106 | }); |
90 | 107 | ||
91 | it('returns cloned object for valid input', () => { | 108 | it('returns cloned object for valid input', () => { |
92 | const result = jsUtils.cleanseJSObject([{a: 'b'}, {c: 'd'}]); | 109 | const result = jsUtils.cleanseJSObject([{ a: 'b' }, { c: 'd' }]); |
93 | expect(result).toEqual([{a: 'b'}, {c: 'd'}]); | 110 | expect(result).toEqual([{ a: 'b' }, { c: 'd' }]); |
94 | }); | 111 | }); |
95 | }); | 112 | }); |
96 | }); | 113 | }); |