I have have a given set of js code:
handleTabKey(evt) {
var code = evt.keyCode || evt.which;
if (code === 9) {
var activeElm = document.activeElement.getAttribute('id');
if (activeElm === 'firstItem') {
$('#skipToMenu').removeClass('menu-invisible').attr('aria-expanded', true);
$('#firstItem').focus();
}
}
}
I need to write unit test case for this function using Mocha and Chai.
I wrote the unit test case like below manner:
describe('handleTabKey()', () => {
it('Set focus to first element on tab', (e) => {
expect(e.keyCode).to.equal(9);
expect(e.which).to.equal(9);
if (e.keyCode === 9 || e.which === 9) {
$('#skipToMenu').$el = {
removeClass: (strClass) => {
bolRemoveClass = true;
expect(strClass).to.equal("menu-invisible");
}
};
expect(view.$el.getElementById('firstItem').focus()).to.equal(true);
}
});
});
But it is not working for me. Instead it by pass the conditions within if.
Kindly help. Thanks in advance.