Karma + Jasmine won't run any test when doing ng test or npm run test on Angular project

64 Views Asked by At
describe('DialogComponent', () => { 
   it('should render DialogComponent', async () => { 
     await render(DialogComponent) 
     expect(screen.getByText('this should fail')).toBeInTheDocument() 
   }) 
 }) 

I have a test like this that should fail, but when doing ng test, karma doesn't seem to find the test and just hangs after displaying some warnings on a few files.

module.exports = function (config) { 
 config.set({ 
   basePath: '', 
   frameworks: ['jasmine', '@angular-devkit/build-angular'], 
   files: [ 
     { pattern: './src/**/*.spec.ts', included: false, watched: true } 
   ], 
   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: { 

     }, 
     clearContext: false
   }, 
   jasmineHtmlReporter: { 
     suppressAll: true
   }, 
   coverageReporter: { 
     dir: require('path').join(__dirname, './coverage/nwtest'), 
     subdir: '.', 
     reporters: [ 
       { type: 'html' }, 
       { type: 'text-summary' } 
     ] 
   }, 
   reporters: ['progress', 'kjhtml'], 
   port: 9876, 
   colors: true, 
   logLevel: config.LOG_INFO, 
   autoWatch: true, 
   browsers: ['Chrome'], 
   singleRun: false, 
   restartOnFileChange: true 
 }); 
};

My Jasmine config looks like this.

...
// Then we find all the tests. 
const context = require.context('./', true, /\.spec\.ts$/); 
// And load the modules. 
context.keys().map(context); 
// Finally, start Karma to run the tests. 
__karma__.start(); 

This is what I do to run karma. What's wrong? It doesn't seem to run anything. It did show an error when I had a conflict with Chai's expect, but now it's fixed, I don't see any test failing or succeeding. I think I need to do something other than ng test, because it's not running anything. It's a boilerplate project using Angular 14. It says connected on socket and doesn't do anything. Is there a way to debug, because I am not getting any warning or error messages.

One thing is when I change toBeInTheDocument to toBeInTheDocumentBogus, it watches the file and then throw an error log, but after correcting it it doesn't run the test or anything and say whether the test passed or not.

0

There are 0 best solutions below