gpt4 book ai didi

angularjs - 测试 Angular 应用程序时遇到问题/错误 : 'DEPRECATION: describe with no children (describe() or it())

转载 作者:行者123 更新时间:2023-12-05 09:27:49 24 4
gpt4 key购买 nike

用这个 artist-detail.spec.ts 运行我的测试后

import { HttpClientModule } from '@angular/common/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterModule } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';

import { ArtistDetailComponent } from './artist-detail.component';

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

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
RouterTestingModule,
RouterModule,
HttpClientModule
],
declarations: [ ArtistDetailComponent ]
})
.compileComponents();
});

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

it('should create', () => {
expect(component).toBeTruthy();
});
});

我得到了这个输出

27 04 2022 18:23:06.651:INFO [launcher]: Starting browser ChromeHeadless27 04 2022 18:23:09.795:INFO [Chrome Headless 100.0.4896.127 (Linux x86_64)]: Connected on socket iATQ5FHffdjRWSTWAAAB with id 92608559Chrome Headless 100.0.4896.127 (Linux x86_64) ERROR: 'DEPRECATION: describe with no children (describe() or it()) is deprecated and will be removed in a future version of Jasmine. Please either remove the describe or add children to it.Error:at at Env.jasmineEnv. [as describe] (http://localhost:9876/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:454:1)at at Object.4911 (http://localhost:9876/karma_webpack/webpack:/src/app/modules/artist/artist-detail/artist-detail.component.spec.ts:8:1)at webpack_require (http://localhost:9876/karma_webpack/webpack:/webpack/bootstrap:19:1)Note: This message will be shown only once. Set the verboseDeprecations config property to true to see every occurrence.'Chrome Headless 100.0.4896.127 (Linux x86_64) ERROR: 'DEPRECATION: describe with no children (describe() or it()) is deprecated and will be removed in a future version of Jasmine. Please either remove the describe or add children to it.Error:at at Env.jasmineEnv. [as describe] (http://localhost:9876/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:454:1)at at Object.4911 (http://localhost:9876/karma_webpack/webpack:/src/app/modules/artist/artist-detail/artist-detail.component.spec.ts:8:1)at webpack_require (http://localhost:9876/karma_webpack/webpack:/webpack/bootstrap:19:1)Note: This message will be shown only once. Set the verboseDeprecations config property to true to see every occurrence.'Chrome Headless 100.0.4896.127 (Linux x86_64) ERROR: 'DEPRECATION: describe with no children (describe() or it()) is deprecated and will be removed in a future version of Jasmine. Please either remove the describe or add children to it.Error:at at Env.jasmineEnv. [as describe] (http://localhost:9876/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:454:1)at at Object.4911 (http://localhost:9876/karma_webpack/webpack:/src/app/modules/artist/artist-detail/artist-detail.component.spec.ts:8:1)at webpack_require (http://localhost:9876/karma_webpack/webpack:/webpack/bootstrap:19:1)Note: This message will be shown only once. Set the verboseDeprecations config property to true to see every occurrence.'ExhibitionDetailComponent✔ should create

如何解决错误:'DEPRECATION'
的问题非常感谢

最佳答案

这个答案没有直接回答上面的问题,但它可能会帮助其他遇到错误的人,因为我在寻找解决方案时一直在这里结束。

错误:

错误:'弃用:描述没有 child (describe() 或 it())

如果在代码命中内部 describeit 函数之前发生错误,就会发生这种情况。所以测试代码永远不会到达内部函数。

在我的例子中,我从 Jasmine v1.3.1 升级到 Jasmine v4,我有以下代码。请注意,我在侦测对象上对 andReturn 进行了不正确的 Jasmine API 调用。因此,测试在到达内部 describe 函数之前就失败了。

define(function(require) {
'use strict';

return describe('Sample test', function () {
var saveMock = jasmine.createSpy('save').andReturn($.Deferred().resolve());

describe('test', function() {
it('should be true', function() {
expect(true).toEqual(true);
});
});
});
});

修复 API 调用,然后修复实际问题并阻止错误 describe with no children 被抛出,因为它可以到达内部 describe

var saveMock = jasmine.createSpy('save').and.returnValue($.Deferred().resolve());

关于angularjs - 测试 Angular 应用程序时遇到问题/错误 : 'DEPRECATION: describe with no children (describe() or it()),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72046913/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com