Angular 9 ошибка тестирования: Зона необходима для asyn c (), но не найдена - PullRequest
0 голосов
/ 29 марта 2020

Как и выше, пытаясь проверить, но получаю сообщение об ошибке

Zone is needed for the async() test helper but could not be found

Я также получаю сообщение об ошибке. Ошибка afterAll Uncaught TypeError: require.context не является функцией TypeError: require.context не является функцией на Object.global.wrappers./Users/edwardthompson/e4repo/evidentia/projects/date-calculator/src/test.ts.zone.js/dist/zone (src / test.ts: 3: 28)

У меня определены сгенерированные test.ts, и angular. json кажется правильно настроенным. Я могу удалить зависимость от asyn c, вставив шаблон, но при этом остается вторая ошибка, которая, по-видимому, подразумевает этот тест .ts не в л oop?

Выдернуть мои волосы. предложения по устранению неполадок? Вы видите что-то, что я не могу?

test.ts:

import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

declare const require: {
    context(
        path: string,
        deep?: boolean,
        filter?: RegExp
    ): {
        keys(): string[];
        <T>(id: string): T;
    };
};

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

angular. json:

"test": {
  "builder": "@angular-devkit/build-angular:karma",
  "options": {
    "main": "projects/date-calculator/src/test.ts",
    "tsConfig": "projects/date-calculator/tsconfig.spec.json",
    "karmaConfig": "projects/date-calculator/karma.conf.js",
    "preserveSymlinks": true
  }
},

сам тест довольно хорош ваниль:

describe('DateCalculatorComponent', () => {
    let component: DateCalculatorComponent;
    let fixture: ComponentFixture<DateCalculatorComponent>;

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            imports: [
                MatCardModule,
                MatToolbarModule,
                MatFormFieldModule,
                FormsModule,
                MatProgressSpinnerModule,
                MatIconModule,
                MatInputModule,
                MatButtonModule,
                CommonModule,
                ClipboardModule,
                EvDirectivesModule
            ],
            declarations: [DateCalculatorComponent],
            providers: [DateCalculatorService]
        }).compileComponents()
            .then(() => {
                fixture = TestBed.createComponent(DateCalculatorComponent);
                component = fixture.componentInstance;
            });
    }));

    fit(`Given an Angular app is running
         Then the component should be defined`, (() => {
        return expect(component).to.not.be.undefined;
    }));
});
...