在测试angular app时出现问题/ ERROR: 'DEPRECATION: describe with



在运行了这个artist-detail. spects

之后
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]:启动浏览器ChromeHeadless27 04 2022 18:23:09.795:INFO [Chrome Headless 100.0.4896.127 (Linux x86_64)]:连接在socket iATQ5FHffdjRWSTWAAAB与id 92608559Chrome Headless 100.0.4896.127 (Linux x86_64) ERROR: 'DEPRECATION: describe with no children (describe() or it())已被弃用,并将在茉莉的未来版本中删除。请删除描述或添加孩子到它。错误:在在Env.jasmineEnv。[as description] (http://localhost:9876/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:454:1)在at Object.4911 (http://localhost:9876/karma_webpack/webpack:/src/app/modules/artist/artist-detail/artist-detail.component. spects:8:1)在webpack_require(http://localhost: 9876/karma_webpack/webpack:/webpack/引导:19:1)注意:此消息将只显示一次。将verboseDeprecations配置属性设置为true以查看每次发生的情况。Chrome Headless 100.0.4896.127 (Linux x86_64) ERROR: 'DEPRECATION: describe with no children (describe() or it())已被弃用,并将在茉莉的未来版本中删除。请删除描述或添加孩子到它。错误:在在Env.jasmineEnv。[as description] (http://localhost:9876/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:454:1)在at Object.4911 (http://localhost:9876/karma_webpack/webpack:/src/app/modules/artist/artist-detail/artist-detail.component. spects:8:1)在webpack_require(http://localhost: 9876/karma_webpack/webpack:/webpack/引导:19:1)注意:此消息将只显示一次。将verboseDeprecations配置属性设置为true以查看每次发生的情况。Chrome Headless 100.0.4896.127 (Linux x86_64) ERROR: 'DEPRECATION: describe with no children (describe() or it())已被弃用,并将在茉莉的未来版本中删除。请删除描述或添加孩子到它。错误:在在Env.jasmineEnv。[as description] (http://localhost:9876/karma_webpack/webpack:/node_modules/zone.js/fesm2015/zone-testing.js:454:1)在at Object.4911 (http://localhost:9876/karma_webpack/webpack:/src/app/modules/artist/artist-detail/artist-detail.component. spects:8:1)在webpack_require(http://localhost: 9876/karma_webpack/webpack:/webpack/引导:19:1)注意:此消息将只显示一次。将verboseDeprecations配置属性设置为true以查看每次发生的情况。ExhibitionDetailComponent✔应该创建

如何解决ERROR: 'DEPRECATION'
谢谢你。

上面的弃用警告并没有告诉您哪个测试有问题。它就像一个总结警告,说其中一个测试有这个问题。

要找出哪些测试需要修复,请添加verboseDeprecations: truejasminekarma.conf.js配置文件(见下文)

client: {
jasmine: {
....
verboseDeprecations: true,
...
},
...
},

然后运行所有或所需的单元测试,并查看具有描述且没有子的每个测试的名称问题和修复那些(添加孩子或删除那些描述)。

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

错误:

ERROR: 'DEPRECATION: describe with no children (describe() or 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());

也有相同的错误。通过指定函数ìt解决。由于您有2xbeforeEach函数,我建议将其写成

it('should create', () => {
const fixture = TestBed.createComponent(ArtistDetailComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});

对于我来说,我在主beforeEach中有一个beforeEachit块。

与下同:

beforeEach(() => {
TestBed.configureTestingModule({});

beforeEach(() => {});

it('abc', () => {});
it('def', () => {});
});

我把它改成:

beforeEach(() => {
TestBed.configureTestingModule({});
});
beforeEach(() => {});
it('abc', () => {});
it('def', () => {});

问题就解决了。

最新更新