Karma + jasmine + angular + ui router - testing for resolve with state.go with params

白昼怎懂夜的黑 提交于 2019-12-05 13:18:37

Finally, I fixed the problem. Here is the solution for any one who is interested in.

1) Import modules

beforeEach(module('stateA'));
   beforeEach(module('stateB'));
   beforeEach(module('ui.router'));

2)

beforeEach(module(


function($provide) {
            $provide.value('$localStorage', mockStorage = { value3: []});
            $provide.value('$stateParams', stateParams = { param1: 1234, param2: "true"});
        }));

3) unit test:

it('should go to stateB.details state and resolve the data', function() {
            mockStorage.assetInfo[stateParams.value3] = 'resolved-data';
            var s = state.get('stateB.details');
            expect(injector.invoke(s.resolve.value3)).toEqual('resolved-data');
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!