When I try and run an ng test, all of my modules and components load correctly, but any of the assets I include in <img>
tags do not render because they're not being served in the /assets folder (like they would in a build or during development using ng serve)
In addition to this, it would be nice to know how to get the global styles.scss/css file to be included in the test, as I can only get these styles to render if I drop the CSS into a component and disable ViewEncapsulation.
I'm on the latest angular-cli webpack release (Beta 15)
Any help is greatly appreciated.
Jasmine and Karma frameworks are used for Unit Testing of the Angular applications.
ng test <project> [options] ng t <project> [options] Description. Takes the name of the project, as specified in the projects section of the angular. json workspace configuration file. When a project name is not supplied, it will execute for all projects.
Disable a Test with @Test( enabled=false ) To disable a test in TestNG, we should set the enabled attribute of the @Test annotation to false . The default attribute value of enabled is true.
I found the answer!
By default, the karma setup in the angular-cli (webpack) doesn't serve your assets folder by default, but this is very simple to add (once you sift through the documentation)
below is a screenshot of my results and the code I added to get it to work
To the left you can see my image of Billy Mays is now being served, to the right if you look at the 'file' section of the json, I added the following:
{ pattern: './src/assets/**', watched: false, included:false, nocache:false, served:true }
I also added a proxies property, to take the served content (served by default at http://localhost:[karma port number]/base
proxies: {
'/assets/': '/base/src/assets/'
},
By specifying /assets/
as the folder proxy, karma uses the path
localhost:[karma port number]/assets
instead of the default.
I'm happy I was able to my own question, and hope this helps some people starting with the angular-cli!
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