5

I intend to write tests using Mocha that can be executed using Karma. When I develop code, the application starts on http://localhost:3000 and I want to run tests (through command line - via GRUNT) that validate the status of the DOM.

How do I configure karma to do that? How do I provide the HTML for that view?

Also, there are multiple pages and each page has a different set of tests. How to architect the solution so that all the tests are executed precisely?

brasofilo
  • 25,496
  • 15
  • 91
  • 179
tusharmath
  • 10,622
  • 12
  • 56
  • 83

1 Answers1

5

I think all you need is Protractor configured with Karma. Here is example (with Jasmine) - https://github.com/angular/angular-seed/blob/master/test/protractor-conf.js.

It can run browser, simulate any action like real "end" user, and check DOM elements.

IProblemFactory
  • 9,551
  • 8
  • 50
  • 66
  • Thanks for your answer. Can you give an example about how to create test suites for specific pages? For example `.../login` page should contain a "button#submit" element and `.../foo` page should contain a "div.bar"? Also, the application is using node + Express, not Angular, would Protractor still be applicable? – utdemir Aug 05 '14 at 13:40
  • E2E tests are not unit tests - you can't test any unit separetly. All what you can and should do, is just to simulate action which can be performed by user, and examine only that what user can see - DOM. – IProblemFactory Aug 05 '14 at 14:11
  • Protractor seems like the right tool for you, but keep in mind using Protractor and Karma together is not recommended: http://stackoverflow.com/questions/17070522/can-protractor-and-karma-be-used-together – rulio Aug 12 '14 at 02:46