1

I am currently using Karma and Jasmine for doing the unit test my first angular App. Now I want to test my App's HTML elements but I couldn't find any way to do that in karma test runner. I read that this is only possible with protractor. I have no idea of writing and running test in protractor, can anyone help me out? OR Suggest if there is a way to test HTML in karma? Because I am using Karma for controller testing, is it possible to test HTML as well in Karma then it'll be super helpful. For protractor, can I test my controller as well in protractor??

Hassan
  • 329
  • 2
  • 10
  • 27

1 Answers1

2

First of all, there are two very different major types of tests/categories that are usually written for AngularJS applications: unit tests and end-to-end tests.

For unit testing of your directives, controllers, services - use karma.

For end-to-end testing - use protractor.


Related quote from the Protractor's FAQ:

Karma is a great tool for unit testing, and Protractor is intended for end to end or integration testing. This means that small tests for the logic of your individual controllers, directives, and services should be run using Karma. Big tests in which you have a running instance of your entire application should be run using Protractor. Protractor is intended to run tests from a user's point of view - if your test could be written down as instructions for a human interacting with your application, it should be an end to end test written with Protractor.

See also:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • it seems that HTML testing is not possible in unit testing? – Hassan Jul 27 '15 at 01:41
  • @Hassan it depends on what do you mean by "HTML testing". You can [test directives](https://docs.angularjs.org/guide/unit-testing#testing-directives). You can test your complete application from the user's perspective in a browser with the help of protractor. – alecxe Jul 27 '15 at 01:44
  • here is HTML First Angular JS App and now i am trying to test this in karma it('should show the number of items in list',function() { expect($('#test').text()).toBe('First Angular JS App'); }); – Hassan Jul 27 '15 at 01:46
  • @Hassan well, this sounds like a UI test and a job for protractor. – alecxe Jul 27 '15 at 01:47
  • @alecexe thanks for your time now what can i do am really confused by angular testing now how can i kickstart very shortly with protractor to test this i mentioned above? – Hassan Jul 27 '15 at 01:51