I have two simple functions. The first function X either takes a number or a string. If it receives a number, I return it double, and if it receives a string, I call another function Y. How can I check if my function X performs function Y when it takes a string as a parameter?
function X(arg) {
if (typeof (arg) === 'String') Y(arg)
else return arg * 2
}
function Y(arg) {
return 'Got empty string'
}
Run codeHide resultWhat I want to do in my test.
describe('A function X that checks data type', function() {
it('should call function Y is argument is a string', function() {
let arg = arguments[0]
expect(Y is called if typeof(arg)).toEqual('string')
})
})
Run codeHide resultA more general answer for these types of problems, where “do X if Y” would be awesome. Thank:)
source
share