GithubHelp home page GithubHelp logo

vue-unit-test-with-jest's Introduction

vue-unit-test-with-jest

desc

test vue unit with jest

note: you can also test your project with Vue CLI 3

project diretory constructor

get detail here

some deps for test

  • vue-test-utils (test vue with offical tool)
  • jest (test with jest framework)
  • babel-jest (for ES2015+ features in tests)
  • vue-jest (for handling *.vue files in tests)
  • jest-serializer-vue (for snapshot tests)

some config

jest.config.js

01.tell Jest to handle *.vue files (jest.config.js)

02.tell Jest to process *.vue files with vue-jest (jest.config.js)

03.tell Jest to snapshot tests for vue (jest.config.js)

04.tell Jest to handle *.js files (jest.config.js)

05.tell Jest to process *.js files with babel-jest (jest.config.js)

06.tell Jest to support the same @ -> src alias mapping in source code (jest.config.js)

07.tell Jest the project root dir (jest.config.js)

08.tell Jest to support mock load static file (jest.config.js)

09.tell Jest to support mock load style file (jest.config.js)

10.tell Jest which file to test (jest.config.js)

11.tell Jest where to save coverage test ouput (jest.config.js)

12.tell Jest which file to coverage test (jest.config.js)

.babelrc

Our default Babel config disables ES modules transpilation because webpack already knows how to handle ES modules(./.babelrc#L5). However, we do need to enable it for our tests because Jest tests are run directly in Node.babelrc.

Also, if our tests are run in a relatively newer version of Node, most of the ES features are already supported - we can tell babel-preset-env to target the Node version we are using. This skips transpiling unnecessary features and makes our tests boot faster.

get detail on .babelrc

To apply these options only for tests, we need to add a separate config under env.test (this will be automatically picked up by babel-jest):

get detail on .babelrc

Build Commands

# install dependencies
npm install
#install tes deps (esstional)
#npm run install:tes
#npm run install:tes:unit
#install dev deps (optional)
#npm run install:dev
#install pro deps (optional)
#npm run install:pro

# dev serve with hot reload at localhost:8080 (optional)
npm run dev

# build for production with minification (optional)
npm run build

# run tests
npm run test 
#npm run test -- -u
#run unit test
npm run test:unit
#run unit test with coverage
npm run test:unit:with-coverage

get more

For detailed explanation on how vue-test-utils work, consult the docs for vue-test-utils.

For detailed explanation on how jest work, consult the docs for jest.

For detailed explanation on how jest-babel work, consult the docs for jest-babel.

For detailed explanation on how vue-jest work, consult the docs for vue-jest.

For detailed explanation on how jest-serializer-vue work, consult the docs for jest-serializer-vue.

author

yemiancheng [email protected]

contributor

Evan You [email protected]

License

MIT

vue-unit-test-with-jest's People

Contributors

ymc-github avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.