npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-test-declarative

v1.2.3

Published

Test Vue components declaratively

Downloads

61

Readme

Introduction

Vue unit testing EZ-mode.

Installation

vue add @vue/unit-jest
vue add @vue/unit-mocha
yarn add --dev vue-test-declarative babel-register babel-polyfill browser-env

Usage

  1. Create a file HelloWorld.vuetest in tests/declarative:
<tests for="@/components/HelloWorld.vue">
  <test name="Contains welcome message">
    <expect text to-match="Welcome" />
  </test>
</tests>
  1. Run npm run test:declarative

More details are available in the API Docs.

Examples

Props

For this example, we'll test the HelloWorld component from the default vue-cli template that we've all seen when starting a new project.

Create a HelloWorld.vuetest file in the tests/declarative directory with these contents:

<tests for="@/components/HelloWorld.vue">
  <test name="Render message correctly" :props="props">
    <expect text to-match="Success!" />
  </test>
</tests>

<script>
let context = {
  props: {
    msg: 'Success!',
  }
};
</script>

This simple test expects for the component text to match "Welcome!" in the rendered HelloWorld component. This component uses a prop named msg to display a welcome message, so we pass one in using our script section.

See all tags and options in the API docs.

Interactions

Here is a test for the official TodoMVC example that shows how interactions (set/trigger) work:

<test name="add a todo">
  <set selector=".new-todo" value="First" />
  <trigger selector=".new-todo" event="keyup.enter" />
  <expect text-of=".todo-list li" to-match="First" />
  <expect text-of=".todo-count" to-match="1 item left" />
</test>

Run tests

npm run test:declarative

This command will generate and run mocha tests for all .vuetest files in your test path (defaults to tests/declarative).

npm run test:declarative -- --keep

This command is the same as above but will not delete the generated mocha tests after running.

vuetest.setup.js

Sometimes your tests will require you to import and register components you are using (like vuetify or element-ui), or run other setup before a test. If you need this functionality, create a vuetest.setup.js file in the tests/declarative directory that defines a variable called localVue. This will be used instead of the default Vue instance when running your tests.

import ElementUI from 'element-ui';
import { createLocalVue } from '@vue/test-utils';

let localVue = createLocalVue();
localVue.use(ElementUI);

Any additional javascript required by your tests can be added to this file, and it will be executed before your tests are run.

In general, any test/component-specific javascript should go into your .vuetest <script> section, while anything global to all tests should go into your vuetest.setup.js file.

Configuration

Create a vuetest.config.json file in your project root. This file may contain options to configure vue-test-declarative. The following options are supported:

testsPath

vue-test-declarative defaults to looking for tests in tests/declarative. Use this config setting if you want to place your .vuetest and vuetest.setup.js files somewhere else.

webpackConfigPath

vue-test-declarative tries to find your webpack config automatically if you are using a vue-cli template. If your webpack.config.js file is in another location, set its path here.

Documentation

👉 API Docs

👉 TodoMVC Example Test Suite

Tips

💡 Set the syntax highlighting in your editor to vue, vue-html, or xml when working with .vuetest files.