0👍
We have done unit test using vue-jest. Here are the steps.
-
Use the following code to set up the crypto property globally. This will allow Jest to access window.crypto and won’t cause any issue.Create a
crypto.mock
file and paste following code.const crypto = require(‘crypto’)
Object.defineProperty(global.self, 'crypto', { value: { getRandomValues: arr => crypto.randomBytes(arr.length) } })
-
Now import this file in your test file component. Now You can use jasmine.Spy to spy on the elements.
let spyFor: jasmine.Spy; spyFor = spyOn(function.hello, 'hello'); expect(spyFor).toHaveBeenCalledTimes(1);
In this way you can mock on the methods. Pls free to ask if you have anything more.
- [Vuejs]-Vue.js- How is the value of v-model and this.pageNumber are changing according to the pagination?
- [Vuejs]-How do you push an object into another object when the data within it gets changed?
Source:stackexchange.com