mocha chai test case for angularjs ui-route

淺唱寂寞╮ 提交于 2019-12-12 04:54:38

问题


I need to cover angularJs config file through mocha chai

i tried

it('should load the page.', inject(function ($location, $rootScope, $state, $httpBackend) {
    $httpBackend.whenGET('scripts/select-line-module/views/select-line.html').respond('<div/>');
    var state = $state.get('selectLine');
    $rootScope.$digest();
    assert.isDefined(state.templateUrl()); 
    expect(state.templateUrl).toBe('scripts/select-line-module/views/select-line.html');
}));

I am able to cover templateUrl function but test case is failing error : undefined is not a function

I feel i am close , but what i am missing here ?


回答1:


You assertation and expectation are changed. You must assert the function templateUrl is defined and expect the function return to be a string.

assert.isDefined(state.templateUrl); expect(state.templateUrl()).toBe('scripts/select-line-module/views/select-line.html');

However, can you check if state is defined? I think it can be undefined.




回答2:


I did it like

it('should load the page.', inject(function ($state) {
    var state = $state.get('selectLine');
    assert.isDefined(state.templateUrl()); 
    expect(state.templateUrl()).to.equal('scripts/select-line-module/views/select-line.html');
}));

This works for me



来源:https://stackoverflow.com/questions/28719108/mocha-chai-test-case-for-angularjs-ui-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!