Skip to content

Instantly share code, notes, and snippets.

@shinofara
Created June 13, 2013 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinofara/5773314 to your computer and use it in GitHub Desktop.
Save shinofara/5773314 to your computer and use it in GitHub Desktop.
【javascriptを使う人に知って貰いたい(エンジニア、デザイナ問わず)】karmaを使ったテスト駆動開発入門(ついでにJasmineも) ref: http://qiita.com/shinofara/items/b3677ffdfc0c7e45e8d4
$ mkdir -p karma/spec
$ mkdir -p karma/src
$ cd karma
$ npm install -g karma
INFO [watcher]: Changed file "/work/karma/spec/HelloSpec.js".
Chrome 27.0 (Mac): Executed 1 of 1 SUCCESS (0.293 secs / 0.011 secs)
$ karma init
Which testing framework do you want to use ?
Press tab to list possible options. Enter to move to the next question.
> jasmine
Do you want to use Require.js ?
This will add Require.js adapter into files.
Press tab to list possible options. Enter to move to the next question.
> no
Do you want to capture a browser automatically ?
Press tab to list possible options. Enter empty string to move to the next question.
> Chrome
>
Which files do you want to test ?
You can use glob patterns, eg. "js/*.js" or "test/**/*Spec.js".
Enter empty string to move to the next question.
>
Any files you want to exclude ?
You can use glob patterns, eg. "**/*.swp".
Enter empty string to move to the next question.
>
Do you want Testacular to watch all the files and run the tests on change ?
Press tab to list possible options.
> yes
$ vim karma.conf.js
$ vim spec/HelloSpec.js
$ karma start karma.conf.js
INFO [karma]: Karma server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 27.0 (Mac)]: Connected on socket id FqwLPzInsYRW6baEegdg
Chrome 27.0 (Mac) Hello Test test FAILED
Expected 'test1' to equal 'test'.
Error: Expected 'test1' to equal 'test'.
at null.<anonymous> (work/karma/spec/HelloSpec.js:9:15)
Chrome 27.0 (Mac): Executed 1 of 1 (1 FAILED) (0.107 secs / 0.02 secs)
$ cd work/karma
$ karma start karma.conf.js
$ karma start karma.conf.js
INFO [karma]: Karma server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 27.0 (Mac)]: Connected on socket id FqwLPzInsYRW6baEegdg
Chrome 27.0 (Mac) Hello Test test FAILED
Expected 'test1' to equal 'test'.
Error: Expected 'test1' to equal 'test'.
at null.<anonymous> (work/karma/spec/HelloSpec.js:9:15)
Chrome 27.0 (Mac): Executed 1 of 1 (1 FAILED) (0.107 secs / 0.02 secs)
/**
* http://pivotal.github.io/jasmine/
*/
describe("Hello Test", function() {
it("test", function() {
var a = 'test';//actual テストする値
var e = 'test';//expect 期待値
expect(a).toEqual(e);
});
});
files: [
'spec/*.js'
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment