由于区域.js类型错误而失败的业力测试:无法读取未定义的属性'takeUntil'



正在经历(类型错误:无法读取未定义的属性'takeUntil'(运行此测试。 这与区域.js有关。

组件在应用程序中运行良好,只是测试失败?

更多细节,让你开心

这是我正在尝试测试的组件

// Import: Angular
import {Component, EventEmitter, Injectable, Input, Output} from 
'@angular/core';
// Component
@Component({
  selector: 'currency-input',
  templateUrl: './currency-input.html'
})
@Injectable()
export class CurrencyInput {
  @Input() public currencyValue: string;
  @Input() public valid: boolean;
  @Input() public errorMessage: string;
  @Output() public onChange: any = new EventEmitter();
  public currencyInputChange(e: any): void {
    this.onChange.emit(e);
  }
}

这是测试:

describe('CurrencyInput', () => {
let fixture: ComponentFixture<CurrencyInput> = null;
let instance: any = null;
beforeEach(async(() => 
   TestUtils.beforeEachCompiler([CurrencyInput]).then(compiled => {
   fixture = compiled.fixture;
   instance = compiled.instance;
   instance.currencyValue = 'some_value';
   fixture.detectChanges();
})));
  it('defined', () => {
    expect(fixture).not.toBeNull();
    expect(instance).not.toBeNull();
  });
});

堆栈跟踪:

TypeError: Cannot read property 'takeUntil' of undefined
    at TextInput.webpackJsonp.../../../../ionic-angular/components/input/input.js.TextInput._enableHideCaretOnScroll Users/larry/Projects/turbo-ionic/node_modules/ionic-angular/components/input/input.js:440:1)
    at new TextInput Users/larry/Projects/turbo-ionic/node_modules/ionic-angular/components/input/input.js:155:1)
    at createClass Users/larry/Projects/turbo-ionic/node_modules/@angular/core/esm5/core.js:12173:1)
    at createDirectiveInstance Users/larry/Projects/turbo-ionic/node_modules/@angular/core/esm5/core.js:12010:22)
    at createViewNodes Users/larry/Projects/turbo-ionic/node_modules/@angular/core/esm5/core.js:13448:38)
    at callViewAction Users/larry/Projects/turbo-ionic/node_modules/@angular/core/esm5/core.js:13880:1)
    at execComponentViewsAction Users/larry/Projects/turbo-ionic/node_modules/@angular/core/esm5/core.js:13789:1)
    at createViewNodes Users/larry/Projects/turbo-ionic/node_modules/@angular/core/esm5/core.js:13476:1)
    at createRootView Users/larry/Projects/turbo-ionic/node_modules/@angular/core/esm5/core.js:13338:1)
    at callWithDebugContext Users/larry/Projects/turbo-ionic/node_modules/@angular/core/esm5/core.js:14739:26)
Error: Uncaught (in promise): TypeError: Cannot read property 'takeUntil' of undefined
    at resolvePromise Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/zone.js:824:1)
    at resolvePromise Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/zone.js:795:1)
    at http://localhost:9876/_karma_webpack_/webpack:/Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/zone.js:873:1
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/zone.js:425:1)
    at ProxyZoneSpec.webpackJsonp.../../../../zone.js/dist/proxy.js.ProxyZoneSpec.onInvokeTask Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/proxy.js:103:1)
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/zone.js:424:1)
    at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/zone.js:192:1)
    at drainMicroTaskQueue Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/zone.js:602:1)
    at <anonymous>
Expected null not to be null.
    at UserContext.<anonymous> Users/larry/Projects/turbo-ionic/src/components/currency-input/currency-input.spec.ts:23:25)
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/zone.js:392:1)
    at ProxyZoneSpec.webpackJsonp.../../../../zone.js/dist/proxy.js.ProxyZoneSpec.onInvoke Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/proxy.js:79:1)
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/zone.js:391:1)
Expected null not to be null.
    at UserContext.<anonymous> Users/larry/Projects/turbo-ionic/src/components/currency-input/currency-input.spec.ts:24:26)
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/zone.js:392:1)
    at ProxyZoneSpec.webpackJsonp.../../../../zone.js/dist/proxy.js.ProxyZoneSpec.onInvoke Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/proxy.js:79:1)
    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke Users/larry/Projects/turbo-ionic/node_modules/zone.js/dist/zone.js:391:1)

尝试从 beforeEach 中删除 fixture.detectChanges(( - 这似乎是返回此错误的常见问题。

相关内容

  • 没有找到相关文章