@vuedoc/test-utils
v1.5.0
Published
Component testing utils for Vuedoc
Downloads
16
Readme
Vuedoc Test Utils
Component testing utils for Vuedoc.
Install
This package is ESM only : Node 16+ is needed to use it and it must be imported instead of required.
npm install --save-dev @vuedoc/test-utils
Usage
Enable Vuedoc Test Utils on your vitest.config.js
file:
// vitest.config.js
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
setupFiles: [
'@vuedoc/test-utils',
],
},
});
Then use the Vuedoc matchers toParseAs
or toParseWithError
:
toParseAs
// my-test.spec.js
import { expect, test } from 'vitest';
test('should success', async () => {
// your vuedoc parsing options
const options = {
filecontent: `
<script setup>
import { computed } from 'vue';
const message = 'Hello, World!';
</script>
`,
};
await expect(options).toParseAs({
errors: [],
warnings: [],
computed: [],
data: [
{
kind: 'data',
name: 'message',
type: 'string',
initialValue: '"Hello, World!"',
keywords: [],
visibility: 'public' },
],
props: [],
methods: [],
});
});
toParseWithError
// my-test.spec.js
import { expect, test } from 'vitest';
test('should success', async () => {
// your vuedoc parsing options
const options = {
filecontent: `
<script setup>
import { computed } from 'vue';
const !message = 'Unexpected token';
</script>
`,
};
await expect(options).toParseWithError('Unexpected token (2:14)');
});
Vuedoc Matcher Interface
interface VuedocMatchers<R = unknown> {
toParseAs(expectedResult: ParsingResult, options?: ToParseAsOptions): R;
toParseWithError(expectedErrorMessage: string, options?: ToParseAsOptions): R;
}
type ToParseAsOptions = {
/**
* By default `globalThis.VUEDOC_FAKE_NODEMODULES_PATHS`
*/
fakeNodeModulesPaths: string[];
};
Contribute
Please follow CONTRIBUTING.md.
Versioning
Given a version number MAJOR.MINOR.PATCH
, increment the:
MAJOR
version when you make incompatible API changes,MINOR
version when you add functionality in a backwards-compatible manner, andPATCH
version when you make backwards-compatible bug fixes.
Additional labels for pre-release and build metadata are available as extensions
to the MAJOR.MINOR.PATCH
format.
See SemVer.org for more details.
License
Under the MIT license. See LICENSE file for more details.