The Flying Maverick
The Flying Maverick

Reputation: 261

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

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

Upvotes: 5

Views: 16577

Answers (4)

AliF50
AliF50

Reputation: 18849

For me, I had a beforeEach and it blocks inside of the main beforeEach.

Similar to below:

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

I changed it to:

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

beforeEach(() => {});

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

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

And the issue went away.

Upvotes: 0

David Ćeranić
David Ćeranić

Reputation: 154

Also had same error. Solved by specifying function ìt. Since you have 2x beforeEach functions I'd suggest writing it like

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

Upvotes: 0

Navigatron
Navigatron

Reputation: 2105

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

Upvotes: 6

Alex Ryltsov
Alex Ryltsov

Reputation: 3003

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).

Upvotes: 4

Related Questions