I have a function which logs something out onblur on a field. How can I trigger the onblur function in unit test?
inputFunction() {
const inputElements = document.querySelectorAll('input, textarea');
inputElements[0].onblur = () => {
return console.log('test');
};
}
Spec file:
describe('inputFunction', () => {
it('should', function() {
// data
const ctrl = new inputController();
const inputs = [angular.element('<input type="text">Test</input>'), angular.element('<input type="text">test</input>')];
spyOn(document, 'querySelectorAll').and.returnValue(inputs);
inputs[0].triggerHandler('blur');
// when
const expect = ctrl.inputFunction();
// expect
expect(expect).toEqual('test');
});
});
Tried with inputs[0].triggerHandler('blur');
but it doesn't work, it doesn't go inside the onblur function in my Unit Test.
How can I trigger onblur
and go inside the onblur function?