vitest-environment-nuxt
Advanced tools
Comparing version 0.8.4 to 0.8.5
@@ -10,6 +10,68 @@ import { EventHandler } from 'h3'; | ||
type OptionalFunction<T> = T | (() => Awaitable<T>); | ||
/** | ||
* `registerEndpoint` allows you create Nitro endpoint that returns mocked data. It can come in handy if you want to test a component that makes requests to API to display some data. | ||
* | ||
* @param url - endpoint name (e.g. `/test/`). | ||
* @param handler - factory function that returns the mocked data. | ||
* @example | ||
* ```ts | ||
* import { registerEndpoint } from 'nuxt-vitest/utils' | ||
* | ||
* registerEndpoint("/test/", () => { | ||
* test: "test-field" | ||
* }) | ||
* ``` | ||
* @see https://github.com/danielroe/nuxt-vitest#registerendpoint | ||
*/ | ||
declare function registerEndpoint(url: string, handler: EventHandler): void; | ||
/** | ||
* `mockNuxtImport` allows you to mock Nuxt's auto import functionality. | ||
* | ||
* @param _name - name of an import to mock. | ||
* @param _factory - factory function that returns mocked import. | ||
* @example | ||
* ```ts | ||
* import { mockNuxtImport } from 'nuxt-vitest/utils' | ||
* | ||
* mockNuxtImport('useStorage', () => { | ||
* return () => { | ||
* return { value: 'mocked storage' } | ||
* } | ||
* }) | ||
* ``` | ||
* @see https://github.com/danielroe/nuxt-vitest#mocknuxtimport | ||
*/ | ||
declare function mockNuxtImport<T = any>(_name: string, _factory: () => T | Promise<T>): void; | ||
/** | ||
* Mock a component, the first argument can be the relative path to the component, or the component name in PascalCase. | ||
* `mockComponent` allows you to mock Nuxt's component. | ||
* | ||
* @param path - component name in PascalCase, or the relative path of the component. | ||
* @param setup - factory function that returns the mocked component. | ||
* @example | ||
* ```ts | ||
* import { mockComponent } from 'nuxt-vitest/utils' | ||
* | ||
* mockComponent('MyComponent', { | ||
* props: { | ||
* value: String | ||
* }, | ||
* setup(props) { | ||
* // ... | ||
* } | ||
* }) | ||
* | ||
* // relative path or alias also works | ||
* mockComponent('~/components/my-component.vue', async () => { | ||
* // or a factory function | ||
* return { | ||
* setup(props) { | ||
* // ... | ||
* } | ||
* } | ||
* }) | ||
* | ||
* // or you can use SFC for redirecting to a mock component | ||
* mockComponent('MyComponent', () => import('./MockComponent.vue')) | ||
* ``` | ||
* @see https://github.com/danielroe/nuxt-vitest#mockcomponent | ||
*/ | ||
@@ -16,0 +78,0 @@ declare function mockComponent<Props, RawBindings = object>(path: string, setup: OptionalFunction<(props: Readonly<Props>, ctx: SetupContext) => RawBindings | RenderFunction>): void; |
{ | ||
"name": "vitest-environment-nuxt", | ||
"version": "0.8.4", | ||
"version": "0.8.5", | ||
"description": "An vitest environment with support for testing code that needs a Nuxt runtime environment.", | ||
@@ -5,0 +5,0 @@ "repository": "danielroe/vitest-environment-nuxt", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32838
835