测试角度应用程序时遇到问题/错误:'弃用:没有子项的描述(describe() 或 it())

The*_*ick 3 testing angularjs karma-jasmine

使用该 Artist-detail.spec.ts 进行测试后

\n
import { HttpClientModule } from '@angular/common/http';\nimport { ComponentFixture, TestBed } from '@angular/core/testing';\nimport { RouterModule } from '@angular/router';\nimport { RouterTestingModule } from '@angular/router/testing';\n\nimport { ArtistDetailComponent } from './artist-detail.component';\n\ndescribe('ArtistDetailComponent', () => {\n  let component: ArtistDetailComponent;\n  let fixture: ComponentFixture<ArtistDetailComponent>;\n\n  beforeEach(async () => {\n    await TestBed.configureTestingModule({\n      imports: [\n        RouterTestingModule,\n        RouterModule,\n        HttpClientModule\n      ],\n      declarations: [ ArtistDetailComponent ]\n    })\n    .compileComponents();\n  });\n\n  beforeEach(() => {\n    fixture = TestBed.createComponent(ArtistDetailComponent);\n    component = fixture.componentInstance;\n    fixture.detectChanges();\n  });\n\n  it('should create', () => {\n    expect(component).toBeTruthy();\n  });\n});\n
Run Code Online (Sandbox Code Playgroud)\n

我得到了这个输出

\n
\n

27 04 2022 18:23:06.651:INFO [启动器]: 启动浏览器 ChromeHeadless\n27 04 2022 18:23:09.795:INFO [Chrome Headless 100.0.4896.127 (Linux x86_64)]: 连接到套接字 iATQ5FHffdjRWSTWAAAB,ID 为 92608 559\nChrome 无头100.0.4896.127 (Linux x86_64) 错误:“弃用:不带子项的描述(describe() 或 it())已弃用,并将在 Jasmine 的未来版本中删除。请删除描述或向其添加子项。\n错误:\nat \nat Env.jasmineEnv。[如描述] (http://localhost:9876/ karma_webpack /webpack:/node_modules/zone.js/fesm2015/zone-testing.js:454:1)\nat \nat Object.4911 (http://localhost: 9876/ karma_webpack /webpack:/src/app/modules/artist/artist-detail/artist-detail.component.spec.ts:8:1)\nat webpack_require (http://localhost:9876/ karma_webpack /webpack:/ webpack/bootstrap:19:1)\n注意:此消息只会显示一次。将 verboseDeprecations 配置属性设置为 true 以查看每次出现的情况。'\nChrome Headless 100.0.4896.127 (Linux x86_64) 错误:'弃用:不带子项的描述(describe() 或 it())已弃用,将来将被删除茉莉花版本。请删除描述或向其添加子项。\n错误:\nat \nat Env.jasmineEnv。[如描述] (http://localhost:9876/ karma_webpack /webpack:/node_modules/zone.js/fesm2015/zone-testing.js:454:1)\nat \nat Object.4911 (http://localhost: 9876/ karma_webpack /webpack:/src/app/modules/artist/artist-detail/artist-detail.component.spec.ts:8:1)\nat webpack_require (http://localhost:9876/ karma_webpack /webpack:/ webpack/bootstrap:19:1)\n注意:此消息只会显示一次。将 verboseDeprecations 配置属性设置为 true 以查看每次出现的情况。'\nChrome Headless 100.0.4896.127 (Linux x86_64) 错误:'弃用:不带子项的描述(describe() 或 it())已弃用,将来将被删除茉莉花版本。请删除描述或向其添加子项。\n错误:\nat \nat Env.jasmineEnv。[如描述] (http://localhost:9876/ karma_webpack /webpack:/node_modules/zone.js/fesm2015/zone-testing.js:454:1)\nat \nat Object.4911 (http://localhost: 9876/ karma_webpack /webpack:/src/app/modules/artist/artist-detail/artist-detail.component.spec.ts:8:1)\nat webpack_require (http://localhost:9876/ karma_webpack /webpack:/ webpack/bootstrap:19:1)\n注意:此消息只会显示一次。将 verboseDeprecations 配置属性设置为 true 以查看每次出现的情况。'\nExhibitionDetailComponent\n\xe2\x9c\x94 应创建

\n
\n

如何解决问题错误:“弃用”
\n非常感谢

\n

Nav*_*ron 5

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

错误:

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);
            });
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

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

var saveMock = jasmine.createSpy('save').and.returnValue($.Deferred().resolve());
Run Code Online (Sandbox Code Playgroud)