Skip to content

Commit 65703d9

Browse files
committed
fix: resolve test failures after dependency updates
1 parent 2329e3e commit 65703d9

5 files changed

Lines changed: 62 additions & 40 deletions

File tree

apps/solidjs-boilerplate/vite.config.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ export default defineConfig({
5555
'**/mocks/**',
5656
],
5757
},
58+
// Enable isolation to prevent test pollution
59+
isolate: true,
5860
// solid needs to be inline to work around
5961
// a resolution issue in vitest:
60-
// deps: {
61-
// inline: [/solid-js/],
62-
// },
63-
// if you have few tests, try commenting one
64-
// or both out to improve performance:
65-
// threads: false,
66-
// isolate: false,
62+
server: {
63+
deps: {
64+
inline: [/solid-js/],
65+
},
66+
},
6767
exclude: [
6868
'**/node_modules/**',
6969
'**/dist/**',
@@ -72,8 +72,7 @@ export default defineConfig({
7272
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress}.config.*',
7373
'**/e2e/**', // Additional e2e directory for Playwright.
7474
'**/mocks/**',
75-
],
76-
deps: {}, // @ https://qiita.com/Stead08/items/762093fe86999fec4e80
75+
]
7776
},
7877
define: process.env.VITEST ? {} : { global: 'window' },
7978
});
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
/* eslint-disable import/no-extraneous-dependencies */
22
import '@testing-library/jest-dom/vitest';
33
import { beforeAll, afterEach, afterAll } from 'vitest';
4+
import { cleanup } from '@solidjs/testing-library';
45

56
import { server } from '@/mocks/server';
67

78
// So this is basically saying any network requests that come through route them to mock service worker instead of the actual network.
89
beforeAll(() => server.listen());
9-
afterEach(() => server.resetHandlers());
10+
afterEach(() => {
11+
server.resetHandlers();
12+
cleanup(); // Add cleanup after each test
13+
});
1014
afterAll(() => server.close());
Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { render, screen, within } from '@solidjs/testing-library';
1+
import { render, screen } from '@solidjs/testing-library';
22
import { expect, describe, test, vi, beforeAll } from 'vitest';
3-
import { mount } from '@vue/test-utils';
43
import { HidingHeader } from '@/index';
54

65
describe('HidingHeader component', () => {
@@ -17,54 +16,57 @@ describe('HidingHeader component', () => {
1716
});
1817

1918
test('should exists', () => {
20-
const wrapper = mount(HidingHeader)
21-
expect(wrapper).toBeTruthy()
19+
const { unmount } = render(() => <HidingHeader>Header</HidingHeader>);
20+
const element = screen.getByRole('banner');
21+
expect(element).toBeTruthy();
22+
unmount();
2223
});
2324

2425
test('is assigned a <div> tag', () => {
25-
render(() => (
26+
const { unmount } = render(() => (
2627
<HidingHeader>Header</HidingHeader>
2728
));
28-
// screen.getByRole('button', { name: '' });
2929

30-
const containerElm = screen.getByRole('banner', { name: '' });
30+
const containerElm = screen.getByRole('banner');
3131
console.log(containerElm.tagName);
3232
expect(containerElm.tagName).toBe('DIV');
33+
unmount();
3334
});
3435

3536
test('is assigned a <header> tag', () => {
36-
render(() => (
37+
const { unmount } = render(() => (
3738
<HidingHeader component="header">Header</HidingHeader>
3839
));
39-
// screen.getByRole('button', { name: '' });
4040

41-
const containerElm = screen.getByRole('banner', { name: '' });
41+
const containerElm = screen.getByRole('banner');
4242
expect(containerElm.tagName).toBe('HEADER');
43+
unmount();
4344
});
4445

4546
test('Top Level element has correct default class assigned', () => {
46-
render(() => (
47+
const { unmount } = render(() => (
4748
<HidingHeader>
4849
<div class="inner">
4950
<p>Header</p>
5051
</div>
5152
</HidingHeader>
5253
));
5354

54-
const containerElm = screen.getByRole('banner', { name: '' });
55+
const containerElm = screen.getByRole('banner');
5556
expect(containerElm).toHaveClass('hidingHeader');
57+
unmount();
5658
});
5759

5860
test('Top Level element has correct default style assigned', () => {
59-
render(() => (
61+
const { unmount } = render(() => (
6062
<HidingHeader>
6163
<div class="inner">
6264
<p>Header</p>
6365
</div>
6466
</HidingHeader>
6567
));
6668

67-
const containerElm = screen.getByRole('banner', { name: '' });
69+
const containerElm = screen.getByRole('banner');
6870

6971
// Bug for `toHaveStyle()` on CSS Custom Property @ https://github.com/testing-library/jest-dom/issues/280
7072
// expect(containerElm).toHaveStyle(`--hidingHeader-height: 0px;`);
@@ -79,57 +81,64 @@ describe('HidingHeader component', () => {
7981
expect(containerElm.style._values).toMatchObject({
8082
'--hidingHeader-height': '0px',
8183
});
84+
unmount();
8285
});
8386

8487
test('Top Level element has correct additional classes assigned', () => {
85-
render(() => (
88+
const { unmount } = render(() => (
8689
<HidingHeader class="bg-black">
8790
<div class="inner">
8891
<p>Header</p>
8992
</div>
9093
</HidingHeader>
9194
));
9295

93-
const containerElm = screen.getByRole('banner', { name: '' });
96+
const containerElm = screen.getByRole('banner');
9497
expect(containerElm).toHaveClass('hidingHeader', 'bg-black');
98+
unmount();
9599
});
96100

97101
test('inner element has correct default class assigned', () => {
98-
render(() => (
102+
const { unmount } = render(() => (
99103
<HidingHeader>
100104
<div class="inner">
101105
<p>Header</p>
102106
</div>
103107
</HidingHeader>
104108
));
105109

106-
const innerElm = screen.getByRole('banner', { name: '' }).querySelector('div');
110+
const containerElm = screen.getByRole('banner');
111+
const innerElm = containerElm.querySelector('div');
107112
expect(innerElm).toHaveClass('hidingHeader-in');
113+
unmount();
108114
});
109115

110116
test('inner element has correct additional classes assigned', () => {
111-
render(() => (
117+
const { unmount } = render(() => (
112118
<HidingHeader innerClass="bg-black">
113119
<div class="inner">
114120
<p>Header</p>
115121
</div>
116122
</HidingHeader>
117123
));
118124

119-
const innerElm = screen.getByRole('banner', { name: '' }).querySelector('div');
125+
const containerElm = screen.getByRole('banner');
126+
const innerElm = containerElm.querySelector('div');
120127
expect(innerElm).toHaveClass('hidingHeader-in', 'bg-black');
128+
unmount();
121129
});
122130

123131
test('should have a element', () => {
124-
render(() => (
132+
const { unmount } = render(() => (
125133
<HidingHeader>
126134
<div class="inner">
127135
<p>Header</p>
128136
</div>
129137
</HidingHeader>
130138
));
131139

132-
const headerElm = screen.getByText(/^Header$/i); // full string match, ignore case
140+
const headerElm = screen.getByText('Header'); // Use exact text match instead of regex
133141
expect(headerElm).toBeInTheDocument();
142+
unmount();
134143
});
135144
});

packages/solid-hiding-header/vite.config.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ export default defineConfig({
3636
provider: 'v8',
3737
reporter: ['text', 'json', 'html', 'lcov'],
3838
},
39+
// Ensure proper cleanup between tests
40+
globals: false,
41+
// Enable isolation to prevent test pollution
42+
isolate: true,
3943
// solid needs to be inline to work around
4044
// a resolution issue in vitest:
41-
// deps: {
42-
// inline: [/solid-js/],
43-
// },
44-
// if you have few tests, try commenting one
45-
// or both out to improve performance:
46-
// threads: false,
47-
// isolate: false,
48-
deps: {}, // @ https://qiita.com/Stead08/items/762093fe86999fec4e80
45+
server: {
46+
deps: {
47+
inline: [/solid-js/],
48+
},
49+
},
4950
},
5051
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
// eslint-disable-next-line import/no-extraneous-dependencies
22
import '@testing-library/jest-dom/vitest';
3+
// eslint-disable-next-line import/no-extraneous-dependencies
4+
import { cleanup } from '@solidjs/testing-library';
5+
// eslint-disable-next-line import/no-extraneous-dependencies
6+
import { afterEach } from 'vitest';
7+
8+
// Automatically cleanup after each test
9+
afterEach(() => {
10+
cleanup();
11+
});

0 commit comments

Comments
 (0)