Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Test Guide

bcullman edited this page Mar 7, 2019 · 1 revision

Testing

Fundamental Vue is tested using Chai, Jest and Vue Test Utils.

Executing Tests

Tests are executed by running:

$ yarn test

By running

yarn test:watch

you make Jest continuously execute tests. This is great when you prefer test driven development.

Writing a new Test

yarn test will execute tests matching the pattern: src/**/__tests__/*.test.{ts,js,vue}. In order to create a test make sure that your test is in a directory called __tests__ and has a matching extension.

A simple component test might look something like this:

import { expect } from 'chai';
import { shallowMount } from '@vue/test-utils';
import Button from '../Button.vue';

describe('Button', () => {
  it('renders default slot when passed', () => {
    const title = 'Button Title';
    const wrapper = shallowMount(Button, {
      slots: {
        default: title,
      },
    });
    expect(wrapper.text()).to.include(title);
  });
});

Guidelines

Consider the following guidelines when writing new tests:

  • Test the core (e.g.: stateless algorithms, utility functions, helper classes) first: Testing those kind of things usually has the highest payoff: Easy to write and heavily used.
  • Each non-trivial component should have at least one test. Using Vue Test Utils is a good idea.
  • Component tests should be general and not test implementation details. Again: Using Vue Test Utils helps to accomplish that goal.

Current State & Going forward

There are not a lot of tests at the time of writing. Fundamental Vue started as a hobby project and thus testing wasn't on the top of the list early on.

Pretty soon new code will require a certain test coverage. We will also add tests for existing components/code over the next couple of weeks. The Boy Scout Rule

Leave your code better than you found it.

will be enforced at some point in the near future.

Clone this wiki locally