Today, while writing unit test for one of my Angular 4 application I wanted to load bootstrap css. My components uses Bootstrap for styling. The problem is when test run they don’t load CSS so they are not rendered correctly during unit tests. Angular 4 relies on Karma as test runner for unit tests. To load your external CSS file like bootstrap, you have to add files option to karma.conf.js. After making the change, run your test cases again.
module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine', '@angular/cli'], singleRun: false, files: [ "node_modules/bootstrap/bootstrap.min.css", "node_modules/jquery/dist/jquery.min.js" ] }); };
just including css file in karma.conf.js doesn’t solve the problem. Is there anything that needs to be done?