Skip to content

Commit 5ea6418

Browse files
authored
feat: expose config from @vue/test-utils (#12)
1 parent 7aa864d commit 5ea6418

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ test('counter button increments the count', async () => {
5757

5858
Unlike `@testing-library/vue`, `vitest-browser-vue` cleans up the component before the test starts instead of after, so you can see the rendered result in your UI. To avoid auto-cleanup, import the `render` function from `vitest-browser-vue/pure`.
5959

60+
## Configuration
61+
62+
You can change the global configuration by modifying the `config` export. You can import it from both `vitest-browser-vue` and `vitest-browser-vue/pure`. See [documentation](https://test-utils.vuejs.org/api/#config).
63+
64+
```js
65+
import { config } from 'vitest-browser-vue'
66+
67+
config.global.mocks = {
68+
$t: text => text
69+
}
70+
```
71+
6072
## Special thanks
6173

6274
- Powered by [`@vue/test-utils`](https://github.com/vuejs/test-utils/)

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { page } from '@vitest/browser/context'
22
import { beforeEach } from 'vitest'
33
import { cleanup, render } from './pure'
44

5-
export { render, cleanup } from './pure'
5+
export { render, cleanup, config } from './pure'
66
export type { ComponentRenderOptions, RenderResult } from './pure'
77

88
page.extend({

src/pure.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { type ComponentMountingOptions, type VueWrapper, mount } from '@vue/test
33
import type { DefineComponent } from 'vue'
44
import { type PrettyDOMOptions, debug, getElementLocatorSelectors } from '@vitest/browser/utils'
55

6+
export { config } from '@vue/test-utils'
7+
68
type ComponentProps<T> = T extends new (...angs: any) => {
79
$props: infer P
810
// eslint-disable-next-line ts/no-empty-object-type

test/render.test.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import { expect, test } from 'vitest'
22
import { page } from '@vitest/browser/context'
3-
import { render } from 'vitest-browser-vue'
3+
import { config, render } from 'vitest-browser-vue'
44
import HelloWorld from './fixtures/HelloWorld.vue'
55
import Slot from './fixtures/Slot.vue'
66
import Counter from './fixtures/Counter.vue'
77
import Async from './fixtures/Async.vue'
88

9+
config.global.components = {
10+
InjectedGlobalComponent: {
11+
template: '<div>Global Component</div>',
12+
},
13+
}
14+
915
test('renders simple component', async () => {
1016
const screen = render(HelloWorld)
1117
await expect.element(page.getByText('Hello World')).toBeVisible()
@@ -43,6 +49,13 @@ test('renders complex slot', async () => {
4349
await expect.element(screen.getByRole('button', { name: 'Hello World' })).toBeVisible()
4450
})
4551

52+
test('injected component works', async () => {
53+
const screen = render({
54+
template: '<InjectedGlobalComponent />',
55+
})
56+
await expect.element(screen.getByText('Global Component')).toBeVisible()
57+
})
58+
4659
test('renders async component', async () => {
4760
const screen = render({
4861
components: { Async },

0 commit comments

Comments
 (0)