angularjs - Call on $state.go not working in unit test -
i work on app based on angular 1.5, angular-ui-router , webpack want make unit tests on module declaration part, on state configuration (i want test source code of resolve part).
all others unit tests of app working fine on 1 looks call $state.go never processed:
describe('simple module', () => { beforeeach(angular.mock.module('ui.router', 'my-app')); let $state; let $location; let $httpbackend; beforeeach(inject((_$location_, _$state_, _$httpbackend_) => { $state = _$state_; $location = _$location_; $httpbackend = _$httpbackend_; })); describe('app.onlinelisting.error', () => { it('go state', () => { const state = 'app.onlinelisting.error'; $state.go(state); // problem here... // $state.current.name empty ('') if $state.go never called // it's not better $location.url , $httpbackend.flush // ... expect($state.current.name).tobe(state); // spy on myservice , expect myservice.getdata has been called // state not reach resolve parts never triggered... }); }); }); here app module:
export default angular.module('my-app', ['oc.lazyload', 'ui.router', mysimplemodule.name]) .config(($stateprovider, ...) => { ... $stateprovider .state('app', { abstract: true, ... } }); there mysimplemodule declaration:
export default angular.module('my-simple-module', [ 'ui.router' ]) .config(($stateprovider) => { $stateprovider .state('app.onlinelisting', { url: '/onlinelisting', abstract: true, views: { body: { template: '<ui-view />' } } }) .state('app.onlinelisting.error', { url: '/error', template: require('./configurationerror/configurationerror.html'), controller: 'onlinelistingconfigurationerrorctrl', controlleras: 'controller', resolve: { // @nginject modules: ($q, $oclazyload) => { return $q((resolve) => { require(['./configurationerror/configurationerror.js'], (module) => { resolve($oclazyload.load({ name: module.default })); }); }); }, fetcheddata: (myservice) => { // want test check if getdata called return myservice.getdata(); } } }) }); edit
i try this tutorial (which try achieve) it's not working better.
Comments
Post a Comment