[Fixed] Why is Karma is skipping over my valid unit test?

Issue

I working with Karma in an Angular 10 project. I’m trying to test selectors and I can see by running npm run test-report that the file shows up in the all files list, but when I run the test I can see the file is skipped. I even tried to put an f before the describe and karma still skips over it. This test is nearly identically to other tests I’ve run that work so it’s puzzling. See the relevant selector.spec file code and my karma config below.

import { SupportState } from './reducers';
import { supportConfig } from './support.constant';
import * as selectors from './support.selectors';

fdescribe('SupportSelectors', () => {
    let supportConfiguration;
    let myFaqs;

    let state: SupportState;

    beforeEach(() => {
       supportConfiguration = supportConfig;

        myFaqs = {
            answer: "<p>Once signed in to Member Online Services, you can find out if you have coverage for Durable Medica;",
            question: "Am I covered for Durable Medical Equipment (DME) such as breast pumps, sleep apnea machines and orthotics???",
            id: 15,
            name: "Benefits"
        }

        state = {
            config: supportConfiguration,
            faqs: myFaqs,
            category: myFaqs.name,
            error: undefined
        };

       it('should return the configuration for Support', () => {
            expect(selectors.selectSupportConfig.projector(state)).toEqual(supportConfiguration);
        });

        it('should return faqs', () => {
            expect(selectors.selectSupportFAQs.projector(state)).toEqual(myFaqs);
        });

        it('should return category', () => {
            expect(selectors.selectSupportFAQCategory.projector(state)).toEqual(myFaqs.name);
        });

    });
});

Karma.conf.js

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
    config.set({
        basePath: '',
        frameworks: ['jasmine', '@angular-devkit/build-angular'],
        plugins: [
            require('karma-jasmine'),
            require('karma-chrome-launcher'),
            require('karma-jasmine-html-reporter'),
            require('karma-coverage-istanbul-reporter'),
            require('@angular-devkit/build-angular/plugins/karma'),
        ],
        client: {
            clearContext: false, // leave Jasmine Spec Runner output visible in browser
        },
        coverageIstanbulReporter: {
            dir: require('path').join(__dirname, './coverage/member-portal'),
            reports: ['html', 'lcovonly', 'text-summary'],
            fixWebpackSourcePaths: true,
        },
        reporters: ['progress', 'kjhtml'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        browserNoActivityTimeout: 60000,
        browserDisconnectTimeout: 60000,
        autoWatch: true,
        browsers: ['Chrome', 'ChromeHeadless'],
        singleRun: false,
        customLaunchers: {
            ChromeHeadless: {
                base: 'Chrome',
                flags: ['--headless', '--disable-gpu', '--no-sandbox', '--remote-debugging-port=9222'],
            },
        },
        restartOnFileChange: true,
    });
};

Solution

It looks as though your it() expectations are nested within your beforeEach block. They should be peers of beforeEach, or directly under the nearest describe.

Leave a Reply

(*) Required, Your email will not be published