I'm trying to write test for knockout feature with jasmine as below and I'm getting following error:
Error: You cannot apply bindings multiple times to the same element.
describe("ThreeStepNavigationView", ()=> {
var testSubject;
var SmallNavigationStates = ['ribbon','expanded'];
var ExtraSmallNavigationStates = ['collapsed','ribbon','expanded'];
beforeEach(()=> {
loadFixtures('SidebarAndSiteHeader.html');
testSubject = new Mobile.Navigation.ThreeStepNavigation.View();
ko.applyBindings(testSubject);
});
describe('When user clicks on navigation toggle button', ()=>{
it('Should update state class name to the next state', ()=>{
var button = $('#MobileMainNavLink');
var currentScreenSize = Mobile.Helpers.getScreenSize();
button.click();
var classValue = $("#sidebar-wrapper").attr('class');
if (currentScreenSize == 'ExtraSmall') {
expect(classValue).toBe(ExtraSmallNavigationStates[1]);
}
if (currentScreenSize == 'Small') {
expect(classValue).toBe(SmallNavigationStates[1]);
}
});
});
I did try resetting ko as but the result is the same.
afterEach(()=>{
ko.cleanNode($('#MobileMainNavLink')[0]);
ko.cleanNode($('#sidebar-wrapper')[0]);
});
Based on ko documentation cleanNode is an internal function and is not part of the API.
I'm using ko 3.2 and jasmine 1.5