自从将Angular升级到2.3.1后,尝试分配给只读属性

Seb*_*ien 9 testing karma-jasmine angular

我今天早上将Angular 2.1.0项目升级到2.3.1,从那时起我的86个测试中有5个失败,出现以下错误:

失败:尝试分配给只读属性.set @ webpack:///~/@angular/core/src/facade/errors.js:43:33 < - src/test.ts:12465:52

这是最简单的失败测试:

/* tslint:disable:no-unused-variable */
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {ProfileComponent} from './profile.component';
import {TranslateModule, TranslateService} from 'ng2-translate';
import {FormsModule} from '@angular/forms';
import {ProfileService} from '../profile.service';
import {ProfileServiceStub} from '../../../testing/profile-service-stub';
import {TranslateServiceStub} from '../../../testing/translate-service-stub';
import {NotificationsServiceStub} from '../../../testing/notifications-service-stub';
import {NotificationsService} from 'angular2-notifications';

describe('ProfileComponent', () => {
  let component: ProfileComponent;
  let fixture: ComponentFixture<ProfileComponent>;
  const profileServiceStub = new ProfileServiceStub(5000);

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ProfileComponent],
      imports: [
        TranslateModule, FormsModule
      ],
      providers: [
        {provide: ProfileService, useValue: profileServiceStub},
        {provide: TranslateService, useClass: TranslateServiceStub},
        {provide: NotificationsService, useClass: NotificationsServiceStub}
      ]
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ProfileComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});
Run Code Online (Sandbox Code Playgroud)

我没有看到测试设置方式有任何结构差异,所以我猜它与我正在做的事情有关.

当我查看errors.js时,被控制的行看起来像这样:

set: function (message) { this._nativeError.message = message; },
Run Code Online (Sandbox Code Playgroud)

我真的不知道如何解决这个问题.

Seb*_*ien 5

我弄清楚问题是什么.我console.log()在errors.js文件中添加了一个报告错误的文件,并获得了有关上下文的更多信息.事实上,我正在使用存根来进行那些错过特定EventEmitter的测试.这引发了一个错误,但错误报告中似乎存在一个错误,导致karma无法输出正确的消息.

console.log() 是你的朋友