Having problems with testing angular app / ERROR: 'DEPRECATION: describe with no children (describe() or it())

Viewed 2948

After runned my test with this 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();
  });
});

I have got this output

27 04 2022 18:23:06.651:INFO [launcher]: Starting browser ChromeHeadless 27 04 2022 18:23:09.795:INFO [Chrome Headless 100.0.4896.127 (Linux x86_64)]: Connected on socket iATQ5FHffdjRWSTWAAAB with id 92608559 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.' 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

How can I fix the issue ERROR: 'DEPRECATION'
Thanks a lot

2 Answers

The above deprecation warning does not tell you which test has the problem. It is just like a summary warning saying that one of the test(s) have this problem.

To found out which tests need to be fixed please add verboseDeprecations: true for jasmine in karma.conf.js config file (see below)

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

Then run all or required unit tests and see the name of each of the tests that has describe with no children problem and fix those (add children or remove those describe).

This answer doesn't directly answer the question above, but it may help others that encounter the error, since I kept ending up here when searching for a solution.

The error:

ERROR: 'DEPRECATION: describe with no children (describe() or it())

This can happen if an error occurs before the code hits the inner describe or it functions. So the test code never reaches the inner functions.

In my case, I was upgrading from Jasmine v1.3.1 to Jasmine v4 and I had the below code. Note that I had the incorrect Jasmine API call for andReturn on a spied object. So the test failed at that point before it could reach the inner describe function.

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);
            });
        });
    });
});

Fixing the API call, then fixed the actual issue and stopped the error describe with no children from being thrown, since it could reach the inner describe

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