Every time that you change the source files to customize your site, you can test your changes by running unit tests and end to end tests. Unit tests are run by using Karma and the End-to-End tests are run by using Protractor.
Run the command
The command compiles the application and test code and starts karma, which opens a browser and displays the test result. Both processes watch pertinent files, write messages to the console, and rerun when they detect changes.
Unit tests are written in Jasmine, which are called specs. Each spec is located in the same folder as the component they are testing. The filename extension must be
.spec.ts, the convention adhered to by
karma.conf.js. For more information on writing specs, look at the Angular Testing guide.
End-to-end tests explore the application as users experience it. In end-to-end testing, one process runs the real application and a second process runs protractor tests that simulate user behavior and assert that the application responds in the browser as expected. Before you run the end-to-end tests, make sure that you are serving the application through
Run the command
npm run e2e.`
End-to-end tests are located in the
test/e2e folder. The filename extension must be
.e2e-spec.js the convention adhered to by
protractor.conf.js. The end-to-End test uses page objects, which are located in the
test\pageobjects folder. Page objects help you write cleaner tests by encapsulating information about the elements on your application page. A page object can be reused across multiple tests, and if the template of your application changes, you need to update only the page object. For more information on writing e2e-specs, look at the Protractor docs.
Updated 10 months ago