JavaScript testing: quick start

How to quickly setup a JS testing with Karma runner and Jasmine:

Install node (http://nodejs.org/download/)
Open the command prompt, and run
npm install -g karma
//Packages are installed to c:\Users\your-user-name\AppData\Roaming
pm
Generate karma config file.
In a command prompt: cd to your development folder, and

karma init

If you get a warning

WARN [init]: No binary for Chrome. Create symlink at "C:\Users\user-name\AppDataLocal\Google\Chrome\Application\chrome.exe", or set "CHROME_BIN" env variable.

then run this command: set CHROME_BIN=C:/Program Files (x86)/Google/Chrome/Application/chrome.exe

Open karma.conf.js, and set files array to files = [JASMINE, JASMINE_ADAPTER, ‘fileWithTests.js’];, where fileWithTest is a test container.

To write tests consult Jasmine help page: http://pivotal.github.io/jasmine/

describe("A suite", function() {
  it("contains spec with an expectation", function() {
    expect(true).toBe(true);
  });
});

Done.

Leave a Reply

Your email address will not be published. Required fields are marked *