问题
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