0
我想测试我的角度1(使用打字稿)模块,并且我遇到的依赖性问题:测试角度子模块找不到依赖
这是我的模块:
app.module.ts
export const appModule: IModule = angular.module('app', [
'ui.router',
'ngMaterial',
'ngMessages',
'ngAnimate',
'angularMoment',
'ngMap',
sharedModule.name,
componentsModule.name
]);
shared.module.ts
export const sharedModule: IModule = angular.module('app.shared', [
'ui.router',
'ngMaterial',
'ngMessages',
'ngAnimate',
'angularMoment',
'ngMap'
]);
但是当测试我得到的错误所有我的测试,但我的项目在浏览器中运行得很好。因此,只有在测试不能找到依赖罚球误差修改是这样的:
Uncaught Error: [$injector:modulerr] Failed to instantiate module app.shared due to:
Error: [$injector:modulerr] Failed to instantiate module ui.router due to:
Error: [$injector:nomod] Module 'ui.router' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
但是当我把我的共享模块:
export const sharedModule: IModule = angular.module('app.shared', []);
那么它的错误只在使用外部测试服务,如:
Error: [$injector:unpr] Unknown provider: $stateProvider <- $state
测试如下:
describe('component: bookmark',() => {
let parentScope: any;
let element: any;
beforeEach(angular.mock.module(sharedModule.name));
beforeEach(inject(($compile: ng.ICompileService, $rootScope: ng.IRootScopeService) => {
parentScope = $rootScope.$new();
element = angular.element(`<bookmark></bookmark>`);
$compile(element)(parentScope);
parentScope.$digest();
}));
it('should display a star',() => {
const someAttrValue: string = findIn(element, 'md-icon').text();
console.debug('found ', someAttrValue);
expect(someAttrValue).toEqual('star');
});
});
和我bookmark
需要$state
任何线索我可能是做错了什么?