|
1 | 1 | import { $, $$ } from '@wdio/globals' |
2 | 2 | import { beforeEach, describe, expect, test, vi } from 'vitest' |
3 | 3 |
|
4 | | -import { getReceived } from '../../__fixtures__/utils.js' |
5 | 4 | import { toHaveText } from '../../../src/matchers/element/toHaveText.js' |
6 | 5 | import type { ChainablePromiseArray } from 'webdriverio' |
7 | 6 |
|
@@ -234,34 +233,43 @@ Expect ${selectorName} to have text |
234 | 233 | expect(el.getText).toHaveBeenCalledTimes(1) |
235 | 234 | }) |
236 | 235 |
|
237 | | - test('not - failure', async () => { |
| 236 | + test('not - failure - pass should be true', async () => { |
238 | 237 | const el = await $('sel') |
239 | | - |
240 | | - vi.mocked(el.getText).mockResolvedValue('WebdriverIO') |
| 238 | + el.getText = vi.fn().mockResolvedValue('WebdriverIO') |
241 | 239 |
|
242 | 240 | const result = await toHaveText.call({ isNot: true }, el, 'WebdriverIO', { wait: 0 }) |
243 | | - const received = getReceived(result.message()) |
244 | 241 |
|
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 | + ) |
247 | 249 | }) |
248 | 250 |
|
249 | | - test("should return false if texts don't match", async () => { |
| 251 | + test('not with no trim - failure - pass should be true', async () => { |
250 | 252 | const el = await $('sel') |
251 | | - vi.mocked(el.getText).mockResolvedValue('WebdriverIO') |
| 253 | + el.getText = vi.fn().mockResolvedValue(' WebdriverIO ') |
252 | 254 |
|
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 }) |
254 | 256 |
|
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 | + ) |
256 | 264 | }) |
257 | 265 |
|
258 | | - test('should return true if texts match', async () => { |
| 266 | + test('not - success - pass should be false', async () => { |
259 | 267 | const el = await $('sel') |
260 | | - vi.mocked(el.getText).mockResolvedValue('WebdriverIO') |
| 268 | + el.getText = vi.fn().mockResolvedValue('WebdriverIO') |
261 | 269 |
|
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 }) |
263 | 271 |
|
264 | | - expect(result.pass).toBe(true) |
| 272 | + expect(result.pass).toBe(false) // success, boolean is inverted later because of `.not` |
265 | 273 | }) |
266 | 274 |
|
267 | 275 | test('should return true if actual text + single replacer matches the expected text', async () => { |
|
0 commit comments