Testing On Angular
As a best practice we need to write tests for every code we write.There are lots of testing frameworks available to use depending on the programming language that we are using and the type of tests that we want to write(Front-end,Back-end,Functional tests,Integration tests)
To start the development we can add Mocha to our project as a development dependency
$ npm install --save-dev mocha
Chai can be installed as a development dependency as following
$ npm install --save-dev chai
We may also require to mock some data or functionalities to make sure unit tests are passing. Sinon is a good toll for that.Sinon allows you to replace the difficult parts of your tests with something that makes testing simple.Sinon helps eliminate complexity in tests by allowing you to easily create so called test-doubles.
If you want to test code making an Ajax call, how can you do that? You need to run a server and make sure it gives the exact response needed for your test. It’s complicated to set up, and makes writing and running unit tests difficult.
Sinon can be installed as following.
$ npm install sinon