0

我已经安装了最新的 angular-cli 并且该应用程序在浏览器中运行但是当我运行ng e2e量角器测试失败时:

[21:25:53] I/direct - Using ChromeDriver directly...
[21:25:53] I/launcher - Running 1 instances of WebDriver
[21:25:56] E/launcher - Error: TSError: ? Unable to compile TypeScript
src\app\user\user.ts (9,12): Property 'assign' does not exist on type 'ObjectConstructor'. (2339)

我认为这意味着我需要一个 polyfill,Object.assign()但是我还没有找到任何有效的简单方法。我试过简单地告诉tsconfig.json目标 es5 但这似乎并没有 polyfill assign。我也尝试过使用 babel-polyfill,但我无法按照设置过程进行操作,所以我不确定我做得是否正确。无论如何,我更喜欢“轻量级”解决方案。

angular-cli我正在寻找与版本 2.3.1(节点 6.9.4)创建的环境兼容的东西

更新:我忘了提到问题出在 TestBed 功能中,我假设它在node而不是浏览器中运行组件。具体失败的代码是:

import { TestBed, ComponentFixture } from '@angular/core/testing';
...
TestBed.configureTestingModule({
  declarations: [LoginComponent],
  providers: [AuthService]
});

我能够通过将我的分配调用破解为(<any>Object).assign( this, values ). 这不需要在浏览器中运行相同的代码,甚至不需要TestBed.configureTestingModule(). 我真的不明白 TestBed 但我正在使用它,因为它似乎是在 e2e-spec 文件中访问组件的方式。

4

0 回答 0