Angular 4 - 失败测试导入brosweranimations模块

时间:2017-05-31 06:49:41

标签: javascript angular

更新到Angular 4.0.0后,我的测试失败

Error: Found the synthetic property @visibilityChanged. Please include either "BrowserAnimationsModule" or "NoopAnimationsModule" in your application. in config/karma-test-shim.js (line 82476)
ZoneAwareError@webpack:///~/zone.js/dist/zone.js:923:0 <- config/karma-test-shim.js:82476:28
checkNoSyntheticProp@webpack:///~/@angular/platform-browser/@angular/platform-browser.es5.js:2945:0 <- config/karma-test-shim.js:17836:24

在karma-test-shim.js中试过这种方法来修复但是没有用

Error.stackTraceLimit = Infinity;

require('core-js/es6');
require('core-js/es7/reflect');

require('zone.js/dist/zone');
require('zone.js/dist/long-stack-trace-zone');
require('zone.js/dist/proxy');
require('zone.js/dist/sync-test');
require('zone.js/dist/jasmine-patch');
require('zone.js/dist/async-test');
require('zone.js/dist/fake-async-test');

var appContext = require.context('../src', true, /\.spec\.ts/);

appContext.keys().forEach(appContext);

var testing = require('@angular/core/testing');
var browser = require('@angular/platform-browser-dynamic/testing');
var animation = require('@angular/platform-browser/animations');

testing.TestBed.initTestEnvironment(
  browser.BrowserDynamicTestingModule,
  browser.platformBrowserDynamicTesting(),
  animation.BrowserAnimationsModule
);

1 个答案:

答案 0 :(得分:0)

BrowserAnimationsModule添加到您的项目ngModule并添加import,如下所示:

import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
.....