Giter VIP home page Giter VIP logo

vue-jest-test's Introduction

vue-jest

Use the jest test framework to unit and integrate test cases for the vuejs project.

Build Setup

# install dependencies
npm install

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

# build for production with minification
npm run build

# build for production and view the bundle analyzer report
npm run build --report

# run unit tests
npm run unit

# run all tests
npm test

For a detailed explanation on how things work, check out the guide and docs for test report.

vue-jest-test's People

Contributors

lenvonsam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

zjmgmj

vue-jest-test's Issues

jest-vue-report运行的时候报错

FAIL test\unit\integration\login.spec.js
● Test suite failed to run

Cannot find module 'undefined/package.json' from 'index.min.js'

  at Resolver.resolveModule (node_modules/[email protected]@jest-resolve/build/index.js:169:17)
  at Object.<anonymous> (node_modules/[email protected]@jest-vue-report/dist/index.min.js:1:119)

Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.714s
Ran all test suites.
Error: Cannot find module 'undefined/package.json'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (F:\website\vue-2.0\node_modules_jest-vue-report@0.1.5@jest-vue-report\dist\index.min.js:1:92)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] unit: jest --config test/unit/jest.conf.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] unit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! D:\wiwi\node\node-cache_logs\2018-07-05T03_21_47_359Z-debug.log

how to test the watch with jest and vue-test-utils

what i want to know is that how can i test the watch with vue-test-utils and jest.
i had tried to do like this.
the code above is to featch data from the server,it will return a object of promise
this.$api.querySexListByGoodsCode(data)
appointment.js

watch: {
addGoodsCodeList () {
const data = {
goodsCode: this.orderInfo.goodsCode,
addGoodsCodes: this.addGoodsCodeListStr
}
console.log('========')
console.log(this.$api.querySexListByGoodsCode)
console.log('========')
this.$api.querySexListByGoodsCode(data).then(res => {
if (res.data.SZ_HEAD.RESP_CODE === 'S0000') {
this.sexs = res.data.SZ_BODY.sexList
} else if (['B0201', 'B0205', 'SE3006', 'SE1004'].includes(res.data.SZ_HEAD.RESP_CODE)) {
this.$router.push({ name: 'login' })
} else {
this.$dialog.toast(res.data.SZ_HEAD.RESP_MSG)
}
})
},

appointment.spec.js

it('this is what i did ', () => {
let addGoodsCodeList
wrapper.setData({
orderInfo: {
goodsCode: 'gds1213223'
},
addGoodsCodeListStr: 'gds1312331231'
})
addGoodsCodeList = jest.spyOn(api, 'querySexListByGoodsCode')
wrapper.vm.$nextTick(() => {
expect(addGoodsCodeList).toBeCalled()
next()
})
addGoodsCodeList.mockClear()
})
but ,i got the wrong message in my terminal
this is the wrong message :
[Vue warn]: Computed property "addGoodsCodeListStr" was assigned to but it has no setter.

found in

--->

console.error node_modules/vue/dist/vue.runtime.common.dev.js:621
[Vue warn]: Error in nextTick: "Error: expect(jest.fn()).toBeCalled()

Expected mock function to have been called, but it was not called.
i hope to get the help to solve to this problem

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.