Skip to content

Commit cd3780b

Browse files
committed
Let's keep only setDefaultOptions and deprecated setOptions
1 parent 2f369d3 commit cd3780b

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Object.defineProperty(expectWithSoft, 'clearSoftFailures', {
5151

5252
export const expect = expectWithSoft
5353

54+
// TODO one day to rename to something more aligned with setDefaultOptions
5455
export const getConfig = (): ExpectWebdriverIO.DefaultOptions => DEFAULT_OPTIONS
5556
export const setDefaultOptions = (options: Partial<ExpectWebdriverIO.DefaultOptions>): void => {
5657
Object.entries(options).forEach(([key, value]) => {
@@ -62,6 +63,10 @@ export const setDefaultOptions = (options: Partial<ExpectWebdriverIO.DefaultOpti
6263
})
6364
})
6465
}
66+
67+
/**
68+
* @deprecated use setDefaultOptions instead
69+
*/
6570
export const setOptions = setDefaultOptions
6671

6772
/**

test/matchers/element/toBeDisplayed.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Received: "not displayed"`
198198
let el: ChainablePromiseElement
199199

200200
beforeEach(async () => {
201-
// Reset to known state before each test
201+
// Set global options to custom values before each test
202202
setOptions({ wait: 99, interval: 101 })
203203
el = await $('sel')
204204
el.isDisplayed = vi.fn().mockResolvedValue(true)

test/options.test.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
import { test, expect, describe, beforeEach, afterEach } from 'vitest'
2-
import { setOptions } from '../src/index.js'
1+
import { test, expect, describe, afterEach } from 'vitest'
2+
import { setDefaultOptions, setOptions } from '../src/index.js'
33
import { DEFAULT_OPTIONS, DEFAULT_OPTIONS_TO_BE_DISPLAYED } from '../src/constants.js'
44

55
describe('setDefaultOptions', () => {
66
const defaultOptions = { ...DEFAULT_OPTIONS }
7-
beforeEach(() => {
8-
// Set global options to custom values before each test
9-
setOptions({ wait: 2000, interval: 100 })
10-
})
117
afterEach(() => {
128
// Reset global options to default values after each test
139
setOptions(defaultOptions)
1410
})
1511

16-
test('setDefaultOptions should update both DEFAULT_OPTIONS_TO_BE_DISPLAYED and DEFAULT_OPTIONS', () => {
12+
test('setOptions should update both DEFAULT_OPTIONS_TO_BE_DISPLAYED and DEFAULT_OPTIONS', () => {
1713
expect(DEFAULT_OPTIONS_TO_BE_DISPLAYED.wait).not.toBe(1234)
1814
expect(DEFAULT_OPTIONS.wait).not.toBe(1234)
1915

@@ -22,5 +18,15 @@ describe('setDefaultOptions', () => {
2218
expect(DEFAULT_OPTIONS_TO_BE_DISPLAYED.wait).toBe(1234)
2319
expect(DEFAULT_OPTIONS.wait).toBe(1234)
2420
})
21+
22+
test('setDefaultOptions should update both DEFAULT_OPTIONS_TO_BE_DISPLAYED and DEFAULT_OPTIONS', () => {
23+
expect(DEFAULT_OPTIONS_TO_BE_DISPLAYED.wait).not.toBe(1234)
24+
expect(DEFAULT_OPTIONS.wait).not.toBe(1234)
25+
26+
setDefaultOptions({ wait: 1234 })
27+
28+
expect(DEFAULT_OPTIONS_TO_BE_DISPLAYED.wait).toBe(1234)
29+
expect(DEFAULT_OPTIONS.wait).toBe(1234)
30+
})
2531
})
2632

0 commit comments

Comments
 (0)