Skip to content

Error while running karma test in angular 17 #348

@abhinavek

Description

@abhinavek

I am running karma test in angular 17 app and getting the below error from karma. Please help to resolve this. Thanks in advance.

20 01 2025 06:18:15.581:ERROR [karma-server]: TypeError: Cannot read properties of undefined (reading 'filter')
    at D:\Abhinav\projects\access_control_management_fe\node_modules\karma\lib\file-list.js:74:12
    at Array.map (<anonymous>)
    at FileList._refresh (D:\Abhinav\projects\access_control_management_fe\node_modules\karma\lib\file-list.js:65:22)
    at FileList.refresh (D:\Abhinav\projects\access_control_management_fe\node_modules\karma\lib\file-list.js:160:29)
    at Server.refreshFiles (D:\Abhinav\projects\access_control_management_fe\node_modules\karma\lib\server.js:167:44)
    at D:\Abhinav\projects\access_control_management_fe\node_modules\@angular-devkit\build-angular\src\tools\webpack\plugins\karma\karma.js:169:25
    at Hook.eval [as callAsync] (eval at create (D:\Abhinav\projects\access_control_management_fe\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:38:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (D:\Abhinav\projects\access_control_management_fe\node_modules\tapable\lib\Hook.js:18:14)
    at Watching._done (D:\Abhinav\projects\access_control_management_fe\node_modules\webpack\lib\Watching.js:314:28)
    at D:\Abhinav\projects\access_control_management_fe\node_modules\webpack\lib\Watching.js:229:21

below is my karma.config.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'],
    files: [
      'src/**/*.spec.js', // Include all test files in the src directory
    ],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      jasmine: {
        // you can add configuration options for Jasmine here
        // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
        // for example, you can disable the random execution with `random: false`
        // or set a specific seed with `seed: 4321`
      },
    },
    jasmineHtmlReporter: {
      suppressAll: true // removes the duplicated traces
    },
    coverageReporter: {
      dir: require('path').join(__dirname, './coverage/access_control_management_fe'),
      subdir: '.',
      reporters: [
        { type: 'html' },
        { type: 'text-summary' }
      ]
    },
    reporters: ['progress', 'kjhtml'],
    browsers: ['Chrome'],
    restartOnFileChange: true
  });
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions