Skip to content

Commit 8d25edd

Browse files
authored
refactor(create-rstack): use Vue Test Utils in templates (#269)
1 parent d5eeb2e commit 8d25edd

8 files changed

Lines changed: 18 additions & 20 deletions

File tree

packages/create-rstack/template-app-vue-js/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"devDependencies": {
2121
"@rsbuild/plugin-vue": "^2.0.1",
2222
"@testing-library/jest-dom": "^7.0.0",
23-
"@testing-library/vue": "^8.1.0",
2423
"@vue/test-utils": "^2.4.11",
2524
"happy-dom": "^20.11.1",
2625
"rstack": "^0.3.5"
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect, test } from 'rstack/test';
2-
import { render, screen } from '@testing-library/vue';
2+
import { mount } from '@vue/test-utils';
33
import App from '../src/App.vue';
44

55
test('renders the main page', () => {
6-
render(App);
7-
expect(screen.getByText('Rstack with Vue')).toBeInTheDocument();
6+
const wrapper = mount(App);
7+
expect(wrapper.element).toHaveTextContent('Rstack with Vue');
88
});

packages/create-rstack/template-app-vue-ts/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"devDependencies": {
2121
"@rsbuild/plugin-vue": "^2.0.1",
2222
"@testing-library/jest-dom": "^7.0.0",
23-
"@testing-library/vue": "^8.1.0",
2423
"@types/node": "^24.13.3",
2524
"@vue/test-utils": "^2.4.11",
2625
"happy-dom": "^20.11.1",
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect, test } from 'rstack/test';
2-
import { render, screen } from '@testing-library/vue';
2+
import { mount } from '@vue/test-utils';
33
import App from '../src/App.vue';
44

55
test('renders the main page', () => {
6-
render(App);
7-
expect(screen.getByText('Rstack with Vue')).toBeInTheDocument();
6+
const wrapper = mount(App);
7+
expect(wrapper.element).toHaveTextContent('Rstack with Vue');
88
});

packages/create-rstack/template-lib-vue-js/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"devDependencies": {
2525
"@rsbuild/plugin-vue": "^2.0.1",
2626
"@testing-library/jest-dom": "^7.0.0",
27-
"@testing-library/vue": "^8.1.0",
2827
"@vue/test-utils": "^2.4.11",
2928
"happy-dom": "^20.11.1",
3029
"rstack": "^0.3.5",
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { expect, test } from 'rstack/test';
2-
import { render, screen } from '@testing-library/vue';
2+
import { mount } from '@vue/test-utils';
33
import Button from '../src/Button.vue';
44

5-
test('The button should have correct background color', async () => {
6-
render(Button, {
5+
test('The button should have correct background color', () => {
6+
const wrapper = mount(Button, {
7+
attachTo: document.body,
78
props: {
89
backgroundColor: '#ccc',
910
label: 'Demo Button',
1011
},
1112
});
12-
const button = screen.getByText('Demo Button');
13-
expect(button).toHaveStyle({
13+
expect(wrapper.get('button').element).toHaveStyle({
1414
backgroundColor: '#ccc',
1515
});
16+
wrapper.unmount();
1617
});

packages/create-rstack/template-lib-vue-ts/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"devDependencies": {
2727
"@rsbuild/plugin-vue": "^2.0.1",
2828
"@testing-library/jest-dom": "^7.0.0",
29-
"@testing-library/vue": "^8.1.0",
3029
"@types/node": "^24.13.3",
3130
"@vue/test-utils": "^2.4.11",
3231
"happy-dom": "^20.11.1",
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { expect, test } from 'rstack/test';
2-
import { render, screen } from '@testing-library/vue';
2+
import { mount } from '@vue/test-utils';
33
import Button from '../src/Button.vue';
44

5-
test('The button should have correct background color', async () => {
6-
render(Button, {
5+
test('The button should have correct background color', () => {
6+
const wrapper = mount(Button, {
7+
attachTo: document.body,
78
props: {
89
backgroundColor: '#ccc',
910
label: 'Demo Button',
1011
},
1112
});
12-
const button = screen.getByText('Demo Button');
13-
expect(button).toHaveStyle({
13+
expect(wrapper.get('button').element).toHaveStyle({
1414
backgroundColor: '#ccc',
1515
});
16+
wrapper.unmount();
1617
});

0 commit comments

Comments
 (0)