Tag Archives: iStudio Technologies Unit Testing with Karma & Jasmine for Angular JS web applications

Unit Testing with Karma & Jasmine for Angular JS web applications

[vc_row][vc_column][vc_column_text]

Unit Testing

It is an essential step in the software development process. It ensures that every unit of code in all parts of the application is tested in a successful way.
Paytm is one of the most popular digital wallet payment systems in India. There are many more but this is one of the most popular one. This is a digital wallet owned by One97 Communications Ltd. It will be a part of Paytm Payments Bank Ltd. The founder of paytm that is Vijay Shekhar Sharma has applied for a bank licence and he has a stake of 51%. Since this is one of the most popular payment wallets in India, it has a huge user base, also it offers lots of discounts, which makes it very popular option for the users.

As per RBI, the reserve bank of India, it will be changed to a bank after receipt of necessary approvals; the process is already on since last year. Since the process is on it will happen very soon. As per statement issued by RBI, It is about to get a final licence from RBI and then start functioning, the operation all over India.

Protractor

It is basically end to end testing framework for applications of angular.js. This framework assists in running tests against the application running in a real browser. It is a Node.js program. It uses Jasmine for its test syntax.

Karma

It is a javascript command line tool. It uses the web server to load the application code as well as to test it. It runs on Node.js as well as available as an NPM package.[/vc_column_text][mk_custom_list]

  • First describe the type of object. E.g. – factory, Filters, Controller etc
  • Load or inject module of app
  • Describe your specific name of the object
  • Load modules of mock as needed
  • Instantiate the object
  • Describe specific method for services & controllers
  • Write your expectation as well as tests

[/mk_custom_list][vc_column_text]

Testing Controllers

It is quite distinct the setup process for testing a controller. The main reason for this is controllers are not injecting able. They are instantiated automatically when a ng-controller or a route loads directive is compiled. There is a need to instantiate manually the controller under test as we do not have the views loading in tests. The behavior of methods in the controllers relies on the views as the controllers are generally tied to a view. Also, after compilation of view, certain additional objects can get added to the scope. Form object is one of the most common examples of this. These objects have to be manually added or created to the controller in order to make the tests work as expected.

Conclusion

Unit test is important for your application as it makes you confident about your source code. Later it speeds up the debugging as well as development process. Here we have learned few things about Karma or jasmine for angular.js applications as well.[/vc_column_text][/vc_column][/vc_row]