chaijs / chai

BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
https://chaijs.github.io
MIT License
8.12k stars 699 forks source link

how to check component methods calledOnce #1367

Open vaasav-kumar opened 3 years ago

vaasav-kumar commented 3 years ago

Your document is not clear of testing vue component methods.
I need to check how many times a component method has been called (or) need to check whether the method has been called or not.

sebamarynissen commented 3 years ago

Have a look at chai-spies for this. It's a plugin which allows you to do something like this:

const chai = require('chai');
const chaiSpies = require('chai-spies');
chai.use(chaiSpies);

let vm = new Vue({ ... });
chai.spy.on(vm, 'someMethod');
doSomething();

expect(vm.someMethod).to.have.been.called();