ReferenceError:注入未定义茉莉花
Posted
技术标签:
【中文标题】ReferenceError:注入未定义茉莉花【英文标题】:ReferenceError: inject is not defined jasmine 【发布时间】:2018-06-26 08:03:32 【问题描述】:注入的问题
beforeEach(() =>
angular.module('app.people', []);
inject(($injector: ng.auto.IInjectorService) =>
$controller = $injector.get<ng.IControllerService>('$controller');
$rootScope = $injector.get<ng.IRootScopeService>('$rootScope');
massterControllerParams =
$rootScope: $rootScope,
eventNames: vdog.eventNames
;
);
sut = $controller<vdog.MasterController>('masterController', massterControllerParams);
);
ReferenceError: inject is not defined
at UserContext.<anonymous> (file:///C:/dev/VirtualDog/VirtualDog/test/spec/masterControllerSpec.js:8:13)
at attempt (file:///C:/dev/VirtualDog/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4289:46)
at QueueRunner.run (file:///C:/dev/VirtualDog/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4217:20)
at QueueRunner.execute (file:///C:/dev/VirtualDog/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4199:10)
at Spec.queueRunnerFactory (file:///C:/dev/VirtualDog/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:909:35)
at Spec.execute (file:///C:/dev/VirtualDog/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:526:10)
at UserContext.fn (file:///C:/dev/VirtualDog/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5340:37)
at attempt (file:///C:/dev/VirtualDog/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4297:26)
at QueueRunner.run (file:///C:/dev/VirtualDog/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4217:20)
at QueueRunner.execute (file:///C:/dev/VirtualDog/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4199:10)
SpecRunner.html
<link rel="shortcut icon" type="image/png" href="../../node_modules/jasmine-core/images/jasmine_favicon.png">
<link rel="stylesheet" href="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
<!-- include jasmine libs here -->
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="../../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script src="../../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
<!-- include bower and node_mobules here... -->
<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/angular-route/angular-route.js"></script>
<script src="../../node_modules/angular-mocks/angular-mocks.js"></script>
我用 jasmine 和 typescript 编写了一个单元测试 我无法运行测试,因为注入 请帮忙
【问题讨论】:
显示您的<script>
s 的顺序。 我认为jasmine.js
应该在angular.js
之前
附在 Q 上
【参考方案1】:
请确保您在测试规范中导入了inject
,具体取决于您的确切需求。在标准的 Angular 项目布局中,这将是:
import inject from '@angular/core/testing';
或
import inject from '@angular/core';
【讨论】:
以上是关于ReferenceError:注入未定义茉莉花的主要内容,如果未能解决你的问题,请参考以下文章
错误 ReferenceError: Angular 电子应用程序中未定义 cv