function foo(a) {
console.log(a);
return a;
}
const fooSpy = spy(foo);
fooSpy('test'); // return: test
fooSpy.callCount(); // out: 1
fooSpy.calledWith('test'); // out: true
fooSpy.calledWith('test123'); // out: false
fooSpy.returned('test'); // out: true
function spy(func) {
let fooSpy = {
callCount: function() {
console.log('testss')
}
}
console.log(func);
if (func === undefined) {
console.log(1);
}
spy.prototype.callCount = function() {
console.log('win')
};
return func;
}
fooSpy.prototype.callCount = function() {
console.log('win')
};
I have an error fooSpy.callCount
is not a function
How can I use fooSpy.callCount
? How to use a function that is inside another and access it from the outside? or maybe there is another way to solve this task?
https://jsfiddle.net/qbvsu7rt/23/ there is u can try to check the console