@vuedoc/test-utils
TypeScript icon, indicating that this package has built-in type declarations

1.5.0 • Public • Published

Vuedoc Test Utils

Component testing utils for Vuedoc.

npm Build status Test coverage Buy me a beer

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, and
  • PATCH 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.

Readme

Keywords

Package Sidebar

Install

npm i @vuedoc/test-utils

Weekly Downloads

59

Version

1.5.0

License

MIT

Unpacked Size

16.9 kB

Total Files

12

Last publish

Collaborators

  • demsking