Wednesday, December 12, 2012

Testing AngularJS app in IntelliJ


Install jsTestDriver plugin for IntelliJ

Ensure that the following files exist within your project

  1. jquery-1.8.3.js
  2. jasmine-1.1.0.js *
  3. JasmineAdapter-1.1.2.js *
  4. angular-resource.js
  5. angular-mocks.js

Create a .jstd file in your project folder.(eg ‘TestConfig.jstd’).The file should be something like this
load:
- path/to/jquery-1.8.3.js
- path/to/jasmine-1.1.0.js
- path/to/JasmineAdapter-1.1.2.js
- path/to/angular.js
- path/to/angular-resource.js
- path/to/angular-mocks.js
- path/to/app,models and controllers
test:
- path/to/testfile.js
view raw TestConfig.jstd hosted with ❤ by GitHub
           

Create a test file. Write your test cases using Jasmine and run them using JsTestDriver plugin. 

Note: if u add angular-mocks.js before jasmine, on running the tests, you may get a reference error - module/inject not defined


* while writing the test cases, IntelliJ prompts to add JasmineAdapter and jasmine you could add them then as well