JavaScript testing quick start

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

Install node (http://nodejs.org/download/)
Open command prompt, and run
npm install -g karma
//Packages are installed to c:Usersyour-user-nameAppDataRoaming
pm
Generate karma config file.
In 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:Usersuser-nameAppDataLocalGoogleChromeApplicationchrome.exe”, or set “CHROME_BIN” env variable.

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 Comment

Your email address will not be published.