-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
236 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
import { expect, it } from 'vitest' | ||
import { describe, expect, it } from 'vitest' | ||
|
||
it('should not mock', () => { | ||
expect(useAutoImportedTarget()).toMatchInlineSnapshot('"the original"') | ||
expect(useAutoImportedNonTarget()).toMatchInlineSnapshot('"the original"') | ||
describe('auto-imports', () => { | ||
it('can use core nuxt composables within test file', () => { | ||
expect(useAppConfig().hey).toMatchInlineSnapshot('false') | ||
}) | ||
|
||
it('can access auto-imported composables from within project', () => { | ||
const state = useSingleState() | ||
expect(state.value).toMatchInlineSnapshot('{}') | ||
state.value.field = 'new value' | ||
expect(state.value.field).toMatchInlineSnapshot('"new value"') | ||
expect(useSingleState().value.field).toMatchInlineSnapshot('"new value"') | ||
}) | ||
|
||
it('should not mock imports that are mocked in another test file', () => { | ||
expect(useAutoImportedTarget()).toMatchInlineSnapshot('"the original"') | ||
expect(useAutoImportedNonTarget()).toMatchInlineSnapshot('"the original"') | ||
}) | ||
}) |
58 changes: 0 additions & 58 deletions
58
examples/app-vitest-full/tests/nuxt/export-define-component.spec.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
describe('plugins', () => { | ||
it('can access injections', () => { | ||
const app = useNuxtApp() | ||
expect(app.$auth.didInject).toMatchInlineSnapshot('true') | ||
expect(app.$router).toBeDefined() | ||
}) | ||
}) |
94 changes: 94 additions & 0 deletions
94
examples/app-vitest-full/tests/nuxt/render-suspended.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { afterEach, describe, expect, it } from 'vitest' | ||
import { renderSuspended } from '@nuxt/test-utils/runtime-utils' | ||
import { cleanup, fireEvent, screen } from '@testing-library/vue' | ||
|
||
import App from '~/app.vue' | ||
import OptionsComponent from '~/components/OptionsComponent.vue' | ||
import WrapperTests from '~/components/WrapperTests.vue' | ||
|
||
describe('renderSuspended', () => { | ||
afterEach(() => { | ||
// since we're not running with Vitest globals when running the tests | ||
// from inside the test server. This means testing-library cannot | ||
// auto-attach the cleanup go testing globals, and we have to do | ||
// it here manually. | ||
if (process.env.NUXT_VITEST_DEV_TEST) { | ||
cleanup() | ||
} | ||
}) | ||
|
||
it('can render components within nuxt suspense', async () => { | ||
const { html } = await renderSuspended(App) | ||
expect(html()).toMatchInlineSnapshot(` | ||
"<div id="test-wrapper"> | ||
<div>This is an auto-imported component</div> | ||
<div> I am a global component </div> | ||
<div>Index page</div><a href="/test"> Test link </a> | ||
</div>" | ||
`) | ||
}) | ||
|
||
it('should render default props within nuxt suspense', async () => { | ||
await renderSuspended(OptionsComponent) | ||
expect(screen.getByRole('heading', { level: 2 })).toMatchInlineSnapshot( | ||
` | ||
<h2> | ||
The original | ||
</h2> | ||
` | ||
) | ||
}) | ||
|
||
it('should render passed props within nuxt suspense', async () => { | ||
await renderSuspended(OptionsComponent, { | ||
props: { | ||
title: 'title from mount suspense props', | ||
}, | ||
}) | ||
expect(screen.getByRole('heading', { level: 2 })).toMatchInlineSnapshot( | ||
` | ||
<h2> | ||
title from mount suspense props | ||
</h2> | ||
` | ||
) | ||
}) | ||
|
||
it('can pass slots to rendered components within nuxt suspense', async () => { | ||
const text = 'slot from mount suspense' | ||
await renderSuspended(OptionsComponent, { | ||
slots: { | ||
default: () => text, | ||
}, | ||
}) | ||
expect(screen.getByText(text)).toBeDefined() | ||
}) | ||
|
||
it('can receive emitted events from components rendered within nuxt suspense', async () => { | ||
const { emitted } = await renderSuspended(WrapperTests) | ||
const button = screen.getByRole('button', { name: 'Click me!' }) | ||
await fireEvent.click(button) | ||
|
||
const emittedEvents = emitted() | ||
expect(emittedEvents.click).toMatchObject( | ||
expect.arrayContaining([ | ||
expect.arrayContaining([expect.objectContaining({ type: 'click' })]), | ||
]) | ||
) | ||
|
||
// since this is a native event it doesn't serialize well | ||
delete emittedEvents.click | ||
expect(emittedEvents).toMatchInlineSnapshot(` | ||
{ | ||
"customEvent": [ | ||
[ | ||
"foo", | ||
], | ||
], | ||
"otherEvent": [ | ||
[], | ||
], | ||
} | ||
`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { mountSuspended } from '@nuxt/test-utils/runtime-utils' | ||
|
||
import App from '~/app.vue' | ||
|
||
describe('routing', () => { | ||
it('defaults to index page', async () => { | ||
expect(useRoute().matched[0].meta).toMatchInlineSnapshot(` | ||
{ | ||
"value": "set in index", | ||
} | ||
`) | ||
}) | ||
|
||
it('allows pushing to other pages', async () => { | ||
await navigateTo('/something') | ||
expect(useNuxtApp().$router.currentRoute.value.path).toEqual('/something') | ||
await nextTick() | ||
expect(useRoute().path).toEqual('/something') | ||
}) | ||
|
||
it('handles nuxt routing', async () => { | ||
const component = await mountSuspended(App, { route: '/test' }) | ||
expect(component.html()).toMatchInlineSnapshot(` | ||
"<div>This is an auto-imported component</div> | ||
<div> I am a global component </div> | ||
<div>/test</div> | ||
<a href="/test"> Test link </a>" | ||
`) | ||
}) | ||
}) |
Oops, something went wrong.