Skip to content

Commit 3f33ee4

Browse files
committed
Fix rebase
1 parent 8f54c06 commit 3f33ee4

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

test/__mocks__/@wdio/globals.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ const getElementMethods = () => ({
2121
getComputedLabel: vi.spyOn({ getComputedLabel: async () => 'Computed Label' }, 'getComputedLabel'),
2222
getComputedRole: vi.spyOn({ getComputedRole: async () => 'Computed Role' }, 'getComputedRole'),
2323
// Null is not part of the type, to fix in wdio one day
24-
getAttribute: vi.spyOn({ getAttribute: async (_attr: string) => null as unknown as string }, 'getAttribute'),
24+
getAttribute: vi.spyOn({ getAttribute: async (_attr: string) => 'some attribute' }, 'getAttribute'),
2525
getSize: vi.spyOn({ getSize: async (prop?: 'width' | 'height') => {
2626
if (prop === 'width') { return 100 }
2727
if (prop === 'height') { return 50 }
2828
return { width: 100, height: 50 } satisfies Size
2929
} }, 'getSize') as unknown as WebdriverIO.Element['getSize'],
30-
getAttribute: vi.spyOn({ getAttribute: async (_attr: string) => 'some attribute' }, 'getAttribute'),
3130
} satisfies Partial<WebdriverIO.Element>)
3231

3332
const elementFactory = (_selector: string, index?: number): WebdriverIO.Element => {

test/matchers/element/toHaveText.test.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { $, $$ } from '@wdio/globals'
22
import { beforeEach, describe, expect, test, vi } from 'vitest'
33

4-
import { getReceived } from '../../__fixtures__/utils.js'
54
import { toHaveText } from '../../../src/matchers/element/toHaveText.js'
65
import type { ChainablePromiseArray } from 'webdriverio'
76

@@ -234,34 +233,43 @@ Expect ${selectorName} to have text
234233
expect(el.getText).toHaveBeenCalledTimes(1)
235234
})
236235

237-
test('not - failure', async () => {
236+
test('not - failure - pass should be true', async () => {
238237
const el = await $('sel')
239-
240-
vi.mocked(el.getText).mockResolvedValue('WebdriverIO')
238+
el.getText = vi.fn().mockResolvedValue('WebdriverIO')
241239

242240
const result = await toHaveText.call({ isNot: true }, el, 'WebdriverIO', { wait: 0 })
243-
const received = getReceived(result.message())
244241

245-
expect(received).not.toContain('not')
246-
expect(result.pass).toBe(true)
242+
expect(result.pass).toBe(true) // failure, boolean is inverted later because of `.not`
243+
expect(result.message()).toEqual(`\
244+
Expect $(\`sel\`) not to have text
245+
246+
Expected [not]: "WebdriverIO"
247+
Received : "WebdriverIO"`
248+
)
247249
})
248250

249-
test("should return false if texts don't match", async () => {
251+
test('not with no trim - failure - pass should be true', async () => {
250252
const el = await $('sel')
251-
vi.mocked(el.getText).mockResolvedValue('WebdriverIO')
253+
el.getText = vi.fn().mockResolvedValue(' WebdriverIO ')
252254

253-
const result = await toHaveText.bind({ isNot: true })(el, 'foobar', { wait: 0 })
255+
const result = await toHaveText.call({ isNot: true }, el, ' WebdriverIO ', { trim: false, wait: 0 })
254256

255-
expect(result.pass).toBe(false)
257+
expect(result.pass).toBe(true) // failure, boolean is inverted later because of `.not`
258+
expect(result.message()).toEqual(`\
259+
Expect $(\`sel\`) not to have text
260+
261+
Expected [not]: " WebdriverIO "
262+
Received : " WebdriverIO "`
263+
)
256264
})
257265

258-
test('should return true if texts match', async () => {
266+
test('not - success - pass should be false', async () => {
259267
const el = await $('sel')
260-
vi.mocked(el.getText).mockResolvedValue('WebdriverIO')
268+
el.getText = vi.fn().mockResolvedValue('WebdriverIO')
261269

262-
const result = await toHaveText.bind({ isNot: true })(el, 'WebdriverIO', { wait: 0 })
270+
const result = await toHaveText.call({ isNot: true }, el, 'not WebdriverIO', { wait: 0 })
263271

264-
expect(result.pass).toBe(true)
272+
expect(result.pass).toBe(false) // success, boolean is inverted later because of `.not`
265273
})
266274

267275
test('should return true if actual text + single replacer matches the expected text', async () => {

0 commit comments

Comments
 (0)