Skip to content

Commit 8004226

Browse files
committed
Better unit tests
1 parent 8041f40 commit 8004226

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

test/matchers/element/toBeDisplayed.test.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { $ } from '@wdio/globals'
44
import { toBeDisplayed } from '../../../src/matchers/element/toBeDisplayed.js'
55
import { executeCommandBe } from '../../../src/utils.js'
66
import { DEFAULT_OPTIONS, DEFAULT_OPTIONS_TO_BE_DISPLAYED } from '../../../src/constants.js'
7-
import { setOptions } from '../../../src/index.js'
7+
import { setDefaultOptions, setOptions } from '../../../src/index.js'
88
import type { ChainablePromiseElement } from 'webdriverio'
99

1010
vi.mock('@wdio/globals')
@@ -198,24 +198,33 @@ Received: "not displayed"`
198198
let el: ChainablePromiseElement
199199

200200
beforeEach(async () => {
201-
// Set global options to custom values before each test
202-
setOptions({ wait: 99, interval: 101 })
201+
setDefaultOptions({ wait: 99, interval: 101 })
203202
el = await $('sel')
204203
el.isDisplayed = vi.fn().mockResolvedValue(true)
205204

206205
})
207206

208207
afterEach(() => {
209-
// Reset options after each test to avoid side effects
210-
setOptions(defaultOptions)
211-
expect(DEFAULT_OPTIONS.wait).not.toBe(99)
208+
setDefaultOptions(defaultOptions)
212209
})
213210

214-
test('should use globally set default options with executeCommandBe', async () => {
215-
await toBeDisplayed.call({}, el)
211+
test('should have legacy setOptions still work', () => {
212+
setOptions({ wait: 102 })
213+
expect(DEFAULT_OPTIONS.wait).toBe(102)
214+
expect(DEFAULT_OPTIONS_TO_BE_DISPLAYED.wait).toBe(102)
215+
})
216216

217+
test('should have affect all DEFAULT_OPTIONS_* options', () => {
217218
expect(DEFAULT_OPTIONS.wait).toBe(99)
219+
expect(DEFAULT_OPTIONS.interval).toBe(101)
220+
218221
expect(DEFAULT_OPTIONS_TO_BE_DISPLAYED.wait).toBe(99)
222+
expect(DEFAULT_OPTIONS_TO_BE_DISPLAYED.interval).toBe(101)
223+
})
224+
225+
test('should use globally set default options with executeCommandBe', async () => {
226+
await toBeDisplayed.call({}, el)
227+
219228
expect(executeCommandBe).toHaveBeenCalledWith(
220229
el,
221230
expect.anything(),

0 commit comments

Comments
 (0)