Skip to content

Commit 8991b28

Browse files
committed
Increase coverage
1 parent d28ffb8 commit 8991b28

5 files changed

Lines changed: 67 additions & 9 deletions

File tree

src/util/executeCommand.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ export async function executeCommand<T>(
4444
if (!singleElementCompareStrategy && !mutipleElementsCompareStrategy) { throw new Error('No condition or customMultipleElementCompareStrategy provided to executeCommand') }
4545

4646
const elementOrArray = element ? element : elements ? elements : undefined
47+
48+
/* v8 ignore next -- @preserve -- should be unreachable due to checks above */
4749
if (!elementOrArray) {
48-
// Should be unreachable due to checks above
4950
throw new Error('No elements to process in executeCommand')
5051
}
5152

@@ -57,7 +58,7 @@ export async function executeCommand<T>(
5758
} else if (singleElementCompareStrategy && elements) {
5859
results = await map(elements, (el: WebdriverIO.Element) => singleElementCompareStrategy(el))
5960
} else {
60-
// To please tsc but never reached due to checks above
61+
/* v8 ignore next -- @preserve -- To please tsc but never reached due to checks above */
6162
throw new Error('Unable to process executeCommand with the provided parameters')
6263
}
6364

test/matchers/element/toHaveWidth.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ Received : [50, 50]`
214214
)
215215
})
216216

217-
test.only('not - failure lte - pass should be true', async () => {
217+
test('not - failure lte - pass should be true', async () => {
218218
elements.forEach(el => el.getSize = vi.fn().mockResolvedValue(50))
219219

220220
const result = await thisNotContext.toHaveWidth(elements, { lte: 51 })
@@ -228,7 +228,7 @@ Received : [50, 50]`
228228
)
229229
})
230230

231-
test.only('not - failure lte only first element - pass should be true', async () => {
231+
test('not - failure lte only first element - pass should be true', async () => {
232232
elements.forEach(el => el.getSize = vi.fn().mockResolvedValue(50))
233233

234234
const result = await thisNotContext.toHaveWidth(elements, [{ lte: 51 }, 51])
@@ -242,7 +242,7 @@ Received : [50, 50]`
242242
)
243243
})
244244

245-
test.only('not - failure gte - pass should be true', async () => {
245+
test('not - failure gte - pass should be true', async () => {
246246
elements.forEach(el => el.getSize = vi.fn().mockResolvedValue(50))
247247

248248
const result = await thisNotContext.toHaveWidth(elements, { gte: 49 })

test/matchers/elements/toBeElementsArrayOfSize.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Received : 2`
9494
)
9595
})
9696

97-
test.only('not - failure - lte - pass should be true', async () => {
97+
test('not - failure - lte - pass should be true', async () => {
9898
const result = await thisNotContext.toBeElementsArrayOfSize(els, { lte: 3 })
9999

100100
expect(result.pass).toBe(true) // failure, boolean is inverted later in .not cases
@@ -106,7 +106,7 @@ Received : 2`
106106
)
107107
})
108108

109-
test.only('not - failure - gte - pass should be true', async () => {
109+
test('not - failure - gte - pass should be true', async () => {
110110
const result = await thisNotContext.toBeElementsArrayOfSize(els, { gte: 1 })
111111

112112
expect(result.pass).toBe(true) // failure, boolean is inverted later in .not cases

test/util/stringUtil.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { describe, expect, test } from 'vitest'
2+
import { isString, toJsonString } from '../../src/util/stringUtil'
3+
4+
describe('stringUtil', () => {
5+
describe(isString, () => {
6+
test('should return true for a string', () => {
7+
expect(isString('hello')).toBe(true)
8+
expect(isString('')).toBe(true)
9+
})
10+
11+
test('should return false for non-string values', () => {
12+
expect(isString(123)).toBe(false)
13+
expect(isString(true)).toBe(false)
14+
expect(isString({})).toBe(false)
15+
expect(isString(null)).toBe(false)
16+
expect(isString(undefined)).toBe(false)
17+
expect(isString([])).toBe(false)
18+
})
19+
})
20+
21+
describe(toJsonString, () => {
22+
test('should return the string as is if input is a string', () => {
23+
expect(toJsonString('hello')).toBe('hello')
24+
})
25+
26+
test('should return JSON string if input is a serializable object', () => {
27+
const obj = { foo: 'bar', num: 123 }
28+
expect(toJsonString(obj)).toBe(JSON.stringify(obj))
29+
})
30+
31+
test('should return string representation if JSON.stringify throws', () => {
32+
const circular: any = { foo: 'bar' }
33+
circular.self = circular
34+
35+
expect(toJsonString(circular)).toBe('[object Object]')
36+
expect(toJsonString(BigInt(9007199254740991))).toBe('9007199254740991')
37+
})
38+
39+
test('should return string representation for other types', () => {
40+
expect(toJsonString(123)).toBe('123')
41+
expect(toJsonString(true)).toBe('true')
42+
expect(toJsonString(null)).toBe('null')
43+
})
44+
45+
test('should handle undefined correctly', () => {
46+
expect(toJsonString(undefined)).toBeUndefined()
47+
})
48+
})
49+
})

test/utils.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,11 @@ Received: "not displayed"`)
291291
beforeEach(() => {
292292
// Success for `.not`
293293
vi.mocked(command).mockResolvedValue(false)
294-
negatedContext = { ...context, isNot: true }
294+
negatedContext = {
295+
expectation: 'displayed',
296+
verb: 'be',
297+
isNot: true
298+
}
295299
})
296300

297301
test('should succeed so pass=false since it is inverted later', async () => {
@@ -433,7 +437,11 @@ Expect ${selectorName} to be displayed
433437
beforeEach(() => {
434438
// Success for `.not`
435439
vi.mocked(command).mockResolvedValue(false)
436-
negatedContext = { ...context, isNot: true }
440+
negatedContext = {
441+
expectation: 'displayed',
442+
verb: 'be',
443+
isNot: true
444+
}
437445
})
438446

439447
test('should succeed so pass=false since it is inverted later', async () => {

0 commit comments

Comments
 (0)