vue-test-loader

0.4.1 • Public • Published

vue-test-loader

Extract custom test blocks into .spec files

Usage

Install the loader:

npm install --save-dev vue-test-loader

Setup vue-loader to pass the test block to the loader:

module.exports = {
  // The rest of the config
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
            'test': 'vue-test-loader'
          },
        }
      }
    ]
  }
}

Write tests inside a custom block:

<template>
  <div />
</template>
 
<script>
export default {
  name: 'example-component'
}
</script>
 
<test>
import { shallow } from 'vue-test-utils'
import ExampleComponent from './ExampleComponent'
 
describe('ExampleComponent', () => {
    test('is div', () => {
      expect(shallow(ExampleComponent).is('div')).toBe(true)
    })
})
</test>

vue-test-loader will create a .spec.js file in a __tests__ directory inside the component directory.

This works best with Jest.

Options

Name Description Default
extension string of file extension '.spec.js'
{
  test: /\.vue$/,
  loader: 'vue-loader',
  options: {
    loaders: {
      'test': [{
          loader: path.resolve(__dirname,'../index.js'),
          options: {
              extension: '.test.js'
          }
      }]
    },
  }
}

Examples

You can see an example project using Jest here

Readme

Keywords

Package Sidebar

Install

npm i vue-test-loader

Weekly Downloads

1

Version

0.4.1

License

MIT

Unpacked Size

172 kB

Total Files

16

Last publish

Collaborators

  • eddyerburgh