lenvonsam / vue-jest-test Goto Github PK
View Code? Open in Web Editor NEWAn example of unit and integration testing of a Vue cli project with Jest as a test tool
An example of unit and integration testing of a Vue cli project with Jest as a test tool
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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.