Skip to content

Commit 72ce8e6

Browse files
fix: replace containing assertions
1 parent 75aa9e9 commit 72ce8e6

File tree

4 files changed

+67
-28
lines changed

4 files changed

+67
-28
lines changed

framework-comparisons/src/components/Card.wdio.tsx

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ describe('Card Component', () => {
99
const { container } = render(<Card />)
1010

1111
const $container = $(container)
12-
await expect($container).toHaveTextContaining('count is 0')
12+
await expect($container).toHaveText(
13+
expect.stringContaining('count is 0')
14+
)
1315
await $container.$('button').click()
14-
await expect($container).toHaveTextContaining('count is 1')
16+
await expect($container).toHaveText(
17+
expect.stringContaining('count is 1')
18+
)
1519
})
1620

1721
it('fails because element is not visible', async () => {
@@ -21,36 +25,48 @@ describe('Card Component', () => {
2125
/**
2226
* text can not be received because element is not visible
2327
*/
24-
await expect($container).not.toHaveTextContaining('count is 0')
28+
await expect($container).not.toHaveText(
29+
expect.stringContaining('count is 0')
30+
)
2531
/**
2632
* fails due to "element not interactable" error
2733
*/
2834
await $container.$('button').click()
29-
await expect($container).not.toHaveTextContaining('count is 1')
35+
await expect($container).not.toHaveText(
36+
expect.stringContaining('count is 1')
37+
)
3038
})
3139

3240
it('fails because element has zero height', async () => {
3341
const { container } = render(<Card sideEffect={SideEffect.ZERO_HEIGHT} />)
3442

3543
const $container = $(container)
36-
await expect($container).toHaveTextContaining('count is 0')
44+
await expect($container).toHaveText(
45+
expect.stringContaining('count is 0')
46+
)
3747
/**
3848
* fails due to "element not interactable: element has zero size" error
3949
*/
4050
await $container.$('button').click()
41-
await expect($container).toHaveTextContaining('count is 1')
51+
await expect($container).toHaveText(
52+
expect.stringContaining('count is 1')
53+
)
4254
})
4355

4456
it('fails because another element is laying over the button', async () => {
4557
const { container } = render(<Card sideEffect={SideEffect.OVERLAYING_ELEMENT} />)
4658

4759
const $container = $(container)
48-
await expect($container).toHaveTextContaining('count is 0')
60+
await expect($container).toHaveText(
61+
expect.stringContaining('count is 0')
62+
)
4963
/**
5064
* fails due to "element click intercepted: Element <button aria-label="counter">...</button> is not clickable at point (68, 402). Other element would receive the click: <div style="...">...</div>" error
5165
*/
5266
await $container.$('button').click()
53-
await expect($container).toHaveTextContaining('count is 1')
67+
await expect($container).toHaveText(
68+
expect.stringContaining('count is 1')
69+
)
5470
})
5571

5672
it('fails because the element is outside the viewport', async () => {
@@ -65,12 +81,16 @@ describe('Card Component', () => {
6581
/**
6682
* this fails nonetheless as element is out of viewport
6783
*/
68-
await expect($container).not.toHaveTextContaining('count is 0')
84+
await expect($container).not.toHaveText(
85+
expect.stringContaining('count is 0')
86+
)
6987

7088
/**
7189
* fails due to "element not interactable" error
7290
*/
7391
await $container.$('button').click()
74-
await expect($container).toHaveTextContaining('count is 1')
92+
await expect($container).toHaveText(
93+
expect.stringContaining('count is 1')
94+
)
7595
})
7696
})

framework-comparisons/src/components/Zoom.wdio.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ describe('Zoom Component', () => {
1313
// zoom in
1414
await browser.action('wheel').scroll({ origin: $container.$('img'), deltaY: -250 }).perform()
1515
await expect($container.$('.react-transform-component'))
16-
.toHaveAttrContaining('style', 'transform: translate(-16px, -16px) scale(1.16)')
16+
.toHaveAttr('style', expect.stringContaining('transform: translate(-16px, -16px) scale(1.16)'))
1717

1818
// zoom out
1919
await browser.action('wheel').scroll({ origin: $container.$('img'), deltaY: 250 }).perform()
2020
await expect($container.$('.react-transform-component'))
21-
.toHaveAttrContaining('style', 'transform: translate(0px, 0px) scale(1)')
21+
.toHaveAttr('style', expect.stringContaining('transform: translate(0px, 0px) scale(1)'))
2222
})
2323

2424
it('can zoom in via gestures', async () => {
@@ -42,7 +42,7 @@ describe('Zoom Component', () => {
4242
])
4343
await browser.pause(5000)
4444
await expect($container.$('.react-transform-component'))
45-
.toHaveAttrContaining('style', 'transform: translate(-16px, -16px) scale(1.16)')
45+
.toHaveAttr('style', expect.stringContaining('transform: translate(-16px, -16px) scale(1.16)'))
4646

4747
// zoom out
4848
await browser.actions([
@@ -59,6 +59,6 @@ describe('Zoom Component', () => {
5959
.up()
6060
])
6161
await expect($container.$('.react-transform-component'))
62-
.toHaveAttrContaining('style', 'transform: translate(0px, 0px) scale(1)')
62+
.toHaveAttr('style', expect.stringContaining('transform: translate(0px, 0px) scale(1)'))
6363
})
6464
})

react-typescript-vite/src/tests/LoginForm.test.tsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,46 @@ describe('LoginForm', () => {
6060

6161
it('should show both validation errors if login is attempted without entering username or password', async () => {
6262
await $btnLogin.click()
63-
await expect($form).toHaveTextContaining('Username is required')
64-
await expect($form).toHaveTextContaining('Password is required')
63+
await expect($form).toHaveText(
64+
expect.stringContaining('Username is required')
65+
)
66+
await expect($form).toHaveText(
67+
expect.stringContaining('Password is required')
68+
)
6569
expect(onLogin).toBeCalledTimes(0)
6670
})
6771

6872
it('should only show password validation error if login is attempted without entering password', async () => {
6973
await $username.setValue(username)
7074
await $btnLogin.click()
71-
await expect($form).not.toHaveTextContaining('Username is required')
72-
await expect($form).toHaveTextContaining('Password is required')
75+
await expect($form).not.toHaveText(
76+
expect.stringContaining('Username is required')
77+
)
78+
await expect($form).toHaveText(
79+
expect.stringContaining('Password is required')
80+
)
7381
expect(onLogin).toBeCalledTimes(0)
7482
})
7583

7684
it('should only show username validation error if login is attempted without entering username', async () => {
7785
await $password.setValue(username)
7886
await $btnLogin.click()
79-
await expect($form).toHaveTextContaining('Username is required')
80-
await expect($form).not.toHaveTextContaining('Password is required')
87+
await expect($form).toHaveText(
88+
expect.stringContaining('Username is required')
89+
)
90+
await expect($form).not.toHaveText(
91+
expect.stringContaining('Password is required')
92+
)
8193
expect(onLogin).toBeCalledTimes(0)
8294
})
8395

8496
it('should not show any validation errors before login is attempted', async () => {
85-
await expect($form).not.toHaveTextContaining('Username is required')
86-
await expect($form).not.toHaveTextContaining('Password is required')
97+
await expect($form).not.toHaveText(
98+
expect.stringContaining('Username is required')
99+
)
100+
await expect($form).not.toHaveText(
101+
expect.stringContaining('Password is required')
102+
)
87103
})
88104
})
89105
})

solidjs-typescript-vite/src/tests/counter.test.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ describe('my component tests', () => {
88

99
it('it starts with zero', async () => {
1010
render(() => <Counter />)
11-
const button = screen.getByRole("button");
11+
const button = screen.getByRole('button');
1212
expect($(button)).toBePresent();
13-
expect($(button)).toHaveTextContaining("Count: 0");
13+
expect($(button)).toHaveText(
14+
expect.stringContaining('Count: 0'));
1415
});
1516

16-
it("it increases its value on click", async () => {
17+
it('it increases its value on click', async () => {
1718
render(() => <Counter />);
18-
const button = screen.getByRole("button");
19+
const button = screen.getByRole('button');
1920
await $(button).click()
20-
expect($(button)).toHaveTextContaining("Count: 1");
21+
expect($(button)).toHaveText(
22+
expect.stringContaining('Count: 1'));
2123
await $(button).click()
22-
expect(button).toHaveTextContaining("Count: 2");
24+
expect(button).toHaveText(
25+
expect.stringContaining('Count: 2'));
2326
});
2427
})

0 commit comments

Comments
 (0)