I have a lot of tests that give warnings.
It's almost impossible to track down which spec file is causing each error without sifting through each spec one by one, enabling and disabling each one. Is there any way I can get the WARN:
to show the file/component/service that's causing it?
spec. ts extension will run. To run your tests using the Angular CLI, you use the ng test command in your terminal. As a result, Karma will open up the default browser and run all the tests written with the aid of Jasmine and will display the outcome of those tests.
The karma. conf. js file is a partial Karma configuration file. The CLI constructs the full runtime configuration in memory, based on application structure specified in the angular. json file, supplemented by karma.
We use the Jasmine-provided it function to define a spec. The first parameter of it is a text description of what the spec will be testing — in this case we have a defined component. The second parameter is a function that will run the test. We then use Jasmine's expect function to define our expectation.
Create an Angular project with jasmine and karma By doing this, the jasmine and karma configuration is resolved for us. Install and create a new project with angular-cli: Install npm -g @angular/cli. Ng new angular-unit-testing angular unit-testing.
I was looking for a good solution (like enable some option in karma.conf.js
for example) but didn't find any...
One way I found is to install this library karma-spec-reporter
(https://www.npmjs.com/package/karma-spec-reporter). It shows you each test executed in order. So to track down warnings you just have to look at the component's name below the warning message.
Example: screen_capture_running_tests.png
In my example warnings are related to EditGroupComponent
To install:
npm i karma-spec-reporter
Then add these lines to your karma.conf.js:
config.set({
...
plugins: [
...
require('karma-spec-reporter')
],
// With extra options if you want
specReporter: {
suppressErrorSummary: false, // do not print error summary
suppressFailed: false, // do not print information about failed tests
suppressPassed: false, // do not print information about passed tests
suppressSkipped: true, // do not print information about skipped tests
showSpecTiming: false, // print the time elapsed for each spec
failFast: false // test would finish with error when a first fail occurs.
},
// And replace 'progress' by 'spec'
reporters: ['spec'],
...
});
If you don't like having another dependencie in your project. Install it, correct all and uninstall it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With