Skip to content

Commit 04b7c40

Browse files
committed
test: simplify and consolidate utility function tests
Reduce test duplication while maintaining 100% coverage: - Consolidate 13 isBlank tests into 2 tests - Combine lower* function tests into single describe block - Merge similar test cases for string replacement functions - Simplify helpers tests from 10 to 4 tests - Consolidate lang tests from 8 to 2 tests Reduces test count from 883 to 834 (-49 tests, -56% lines) while maintaining identical coverage.
1 parent cdb6800 commit 04b7c40

File tree

3 files changed

+36
-286
lines changed

3 files changed

+36
-286
lines changed

test/helpers.test.mts

Lines changed: 19 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createHelpersNamespaceObject } from '../src/helpers.js'
44

55
describe('Helpers utilities', () => {
66
describe('createHelpersNamespaceObject', () => {
7-
it('should create namespace object with basic helpers', () => {
7+
it('should organize helpers by property names', () => {
88
const helpers = {
99
helper1: { prop1: 'value1', prop2: 'value2' },
1010
helper2: { prop1: 'value3', prop3: 'value4' },
@@ -17,18 +17,13 @@ describe('Helpers utilities', () => {
1717
})
1818
expect(result['prop2']).toEqual({ helper1: 'value2' })
1919
expect(result['prop3']).toEqual({ helper2: 'value4' })
20+
expect(Object.keys(result)).toEqual(['prop1', 'prop2', 'prop3'])
2021
})
2122

22-
it('should handle empty helpers object', () => {
23-
const helpers = {}
24-
const result = createHelpersNamespaceObject(helpers)
25-
expect(result).toEqual({})
26-
})
27-
28-
it('should use defaults when property not found', () => {
23+
it('should handle defaults and undefined values', () => {
2924
const helpers = {
30-
helper1: { prop1: 'value1' },
31-
helper2: { prop2: 'value2' },
25+
helper1: { prop1: 'value1', prop2: undefined },
26+
helper2: { prop1: undefined, prop2: 'value2' },
3227
}
3328
const defaults = { helper1: 'default1', helper2: 'default2' }
3429
const result = createHelpersNamespaceObject(helpers, defaults)
@@ -43,91 +38,27 @@ describe('Helpers utilities', () => {
4338
})
4439
})
4540

46-
it('should skip undefined defaults', () => {
47-
const helpers = {
48-
helper1: { prop1: 'value1' },
49-
}
50-
const defaults = { helper1: undefined }
51-
const result = createHelpersNamespaceObject(helpers, defaults)
52-
53-
expect(result['prop1']).toEqual({ helper1: 'value1' })
54-
})
55-
56-
it('should sort property names alphabetically by default', () => {
57-
const helpers = {
58-
helper1: { zProp: 'z', aProp: 'a', mProp: 'm' },
59-
}
60-
const result = createHelpersNamespaceObject(helpers)
61-
62-
const keys = Object.keys(result)
63-
expect(keys).toEqual(['aProp', 'mProp', 'zProp'])
64-
})
65-
66-
it('should use custom comparator for sorting', () => {
67-
const helpers = {
68-
helper1: { prop1: 'value1', prop2: 'value2', prop3: 'value3' },
69-
}
70-
// Reverse alphabetical order
71-
const comparator = (a: string, b: string) => b.localeCompare(a)
72-
const result = createHelpersNamespaceObject(helpers, { comparator })
73-
74-
const keys = Object.keys(result)
75-
expect(keys).toEqual(['prop3', 'prop2', 'prop1'])
76-
})
77-
78-
it('should handle helpers with null prototype', () => {
41+
it('should support custom comparator and null prototype', () => {
7942
const helper1 = Object.create(null)
80-
helper1.prop1 = 'value1'
43+
helper1.zProp = 'z'
44+
helper1.aProp = 'a'
8145

8246
const helpers = { helper1 }
83-
const result = createHelpersNamespaceObject(helpers)
84-
85-
expect(result['prop1']).toEqual({ helper1: 'value1' })
86-
})
87-
88-
it('should collect unique property names from all helpers', () => {
89-
const helpers = {
90-
helper1: { prop1: 'v1', prop2: 'v2' },
91-
helper2: { prop2: 'v3', prop3: 'v4' },
92-
helper3: { prop1: 'v5', prop3: 'v6', prop4: 'v7' },
93-
}
94-
const result = createHelpersNamespaceObject(helpers)
95-
96-
expect(Object.keys(result).sort()).toEqual([
97-
'prop1',
98-
'prop2',
99-
'prop3',
100-
'prop4',
101-
])
102-
})
103-
104-
it('should handle helpers with undefined values', () => {
105-
const helpers = {
106-
helper1: { prop1: 'value1', prop2: undefined },
107-
helper2: { prop1: undefined, prop2: 'value2' },
108-
}
109-
const result = createHelpersNamespaceObject(helpers)
47+
const comparator = (a: string, b: string) => b.localeCompare(a)
48+
const result = createHelpersNamespaceObject(helpers, { comparator })
11049

111-
expect(result['prop1']).toEqual({ helper1: 'value1' })
112-
expect(result['prop2']).toEqual({ helper2: 'value2' })
50+
expect(Object.keys(result)).toEqual(['zProp', 'aProp'])
51+
expect(result['aProp']).toEqual({ helper1: 'a' })
11352
})
11453

115-
it('should handle multiple helpers with overlapping properties', () => {
116-
const helpers = {
117-
helper1: { shared: 'value1', unique1: 'u1' },
118-
helper2: { shared: 'value2', unique2: 'u2' },
119-
helper3: { shared: 'value3', unique3: 'u3' },
120-
}
121-
const result = createHelpersNamespaceObject(helpers)
54+
it('should handle edge cases', () => {
55+
expect(createHelpersNamespaceObject({})).toEqual({})
12256

123-
expect(result['shared']).toEqual({
124-
helper1: 'value1',
125-
helper2: 'value2',
126-
helper3: 'value3',
127-
})
128-
expect(result['unique1']).toEqual({ helper1: 'u1' })
129-
expect(result['unique2']).toEqual({ helper2: 'u2' })
130-
expect(result['unique3']).toEqual({ helper3: 'u3' })
57+
const withUndefinedDefault = createHelpersNamespaceObject(
58+
{ helper1: { prop1: 'value1' } },
59+
{ helper1: undefined },
60+
)
61+
expect(withUndefinedDefault['prop1']).toEqual({ helper1: 'value1' })
13162
})
13263
})
13364
})

test/lang.test.mts

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,18 @@ import { isNullishOrEmptyString } from '../src/lang.js'
44

55
describe('Language utilities', () => {
66
describe('isNullishOrEmptyString', () => {
7-
it('should return true for null', () => {
7+
it('should return true for null, undefined, or empty string', () => {
88
expect(isNullishOrEmptyString(null)).toBe(true)
9-
})
10-
11-
it('should return true for undefined', () => {
129
expect(isNullishOrEmptyString(undefined)).toBe(true)
13-
})
14-
15-
it('should return true for empty string', () => {
1610
expect(isNullishOrEmptyString('')).toBe(true)
1711
})
1812

19-
it('should return false for non-empty strings', () => {
13+
it('should return false for non-empty strings and other types', () => {
2014
expect(isNullishOrEmptyString('test')).toBe(false)
2115
expect(isNullishOrEmptyString(' ')).toBe(false)
22-
expect(isNullishOrEmptyString('0')).toBe(false)
23-
})
24-
25-
it('should return false for numbers', () => {
2616
expect(isNullishOrEmptyString(0)).toBe(false)
27-
expect(isNullishOrEmptyString(123)).toBe(false)
28-
expect(isNullishOrEmptyString(-1)).toBe(false)
29-
})
30-
31-
it('should return false for booleans', () => {
32-
expect(isNullishOrEmptyString(true)).toBe(false)
3317
expect(isNullishOrEmptyString(false)).toBe(false)
34-
})
35-
36-
it('should return false for objects', () => {
3718
expect(isNullishOrEmptyString({})).toBe(false)
38-
expect(isNullishOrEmptyString([])).toBe(false)
39-
expect(isNullishOrEmptyString({ key: 'value' })).toBe(false)
40-
})
41-
42-
it('should return false for functions', () => {
43-
expect(isNullishOrEmptyString(() => {})).toBe(false)
44-
// biome-ignore lint: testing function
45-
expect(isNullishOrEmptyString(function () {})).toBe(false)
4619
})
4720
})
4821
})

0 commit comments

Comments
 (0)