#javascript #typescript #jasmine #kendo-grid #karma-jasmine
Вопрос:
У меня есть тривиальный модульный тест, который проходит, но выдает ошибку «Жгут пытается использовать приспособление, которое уже было уничтожено» при запуске ng test --watch=false
. Происходит ли это потому, что я размещаю свой компонент внутри lt;ng-templategt;
? Кто-нибудь знает, как устранить эту ошибку?
Спецификация менукомпонента
describe("MenuComponent", () =gt; { let testHostFixture: ComponentFixturelt;TestHostComponentgt;; let myMenuHarness: MenuHarness; beforeEach( waitForAsync(() =gt; { TestBed.configureTestingModule({ declarations: [...], imports: [...], providers: [...], }).compileComponents(); }) ); beforeEach(async () =gt; { testHostFixture = TestBed.createComponent(TestHostComponent); myMenuHarness = await TestbedHarnessEnvironment.harnessForFixture( testHostFixture, MenuHarness ); testHostFixture.detectChanges(); }); describe("simple test", () =gt; { it("should pass", async () =gt; { await myMenuHarness.openMenu(); expect(true); }); }); @Component({ selector: `my-test-host-component`, template: `lt;kendo-grid ...gt; lt;ng-template kendoGridColumnMenuTemplate let-service="service"gt; lt;app-my-menu [service]="service"gt;lt;/app-my-menugt; lt;/ng-templategt; lt;kendo-grid-column ... gt;lt;/kendo-grid-columngt; lt;/kendo-gridgt;`, }) class TestHostComponent { @ViewChild(MenuComponent) public menu?: MenuComponent; } });
МенуХарнесс
public async openColumnMenu() { const element = await this.queryColumnMenuButton(); element?.click(); }
Выход
Error: Harness is attempting to use a fixture that has already been destroyed. at http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/cdk/fesm2020/testing/testbed.mjs:720:23 at Generator.next (lt;anonymousgt;) at asyncGeneratorStep (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular-devkit/build-angular/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:3:1) at _next (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular-devkit/build-angular/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:25:1) at http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular-devkit/build-angular/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:32:1 at new ZoneAwarePromise (http://localhost:9877/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:1340:1) at http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular-devkit/build-angular/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:21:1 at TestbedHarnessEnvironment.forceStabilize (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/cdk/fesm2020/testing/testbed.mjs:717:28) at UnitTestElement._stabilize (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/cdk/fesm2020/testing/testbed.mjs:751:56) at http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/cdk/fesm2020/testing/testbed.mjs:449:20, 'Error: Harness is attempting to use a fixture that has already been destroyed. at http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/cdk/fesm2020/testing/testbed.mjs:720:23 at Generator.next (lt;anonymousgt;) at asyncGeneratorStep (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular-devkit/build-angular/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:3:1) at _next (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular-devkit/build-angular/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:25:1) at http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular-devkit/build-angular/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:32:1 at new ZoneAwarePromise (http://localhost:9877/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:1340:1) at http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular-devkit/build-angular/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:21:1 at TestbedHarnessEnvironment.forceStabilize (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/cdk/fesm2020/testing/testbed.mjs:717:28) at UnitTestElement._stabilize (http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/cdk/fesm2020/testing/testbed.mjs:751:56) at http://localhost:9877/_karma_webpack_/webpack:/node_modules/@angular/cdk/fesm2020/testing/testbed.mjs:449:20'