USAGE: jasmine-node [--color|--noColor][--verbose][--coffee] directory
Options:
--color - use color coding for output
--noColor - do not use color coding for output
-m, --match REGEXP - load only specs containing "REGEXPspec" --verbose - print extra information per each test run
--coffee - load coffee-script which allows execution .coffee files
--junitreport - export tests results as junitreport xml format
--teamcity - converts all console output to teamcity custom test runner commands. (Normally auto detected.) --runWithRequireJs - loads all specs using requirejs instead of node's native require method
--test-dir - the absolute root directory path where tests are located
--nohelpers - does not load helpers.
-h, --help - display this help and exit
描述一下这个单元测试
算数的结果总是比较容易预测
Failures:
1) 算数的结果总是比较容易预测
Message:
Expected 3 to equal 0.
Stacktrace:
Error: Expected 3 to equal 0.
at new <anonymous> (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:102:32) at [object Object].toEqual (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1171:29) at [object Object].<anonymous> (/users/neekey/Desktop/mhevery-jasmine-node-d3dc963/spec/TestSpec.js:4:19) at [object Object].execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1001:15) at [object Object].next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31) at [object Object].start (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8) at [object Object].execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2070:14) at [object Object].next_ (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1790:31) at [object Object].start (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:1743:8) at [object Object].execute (/usr/local/lib/node_modules/jasmine-node/lib/jasmine-node/jasmine-2.0.0.rc1.js:2215:14)Finished in 0.011 seconds
1 test, 1 assertion, 1 failure
it('should be a test',function(){runs(function(){this.foo=0this.foo++;varbar=0;bar++;expect(this.foo).toEqual(1);expect(bar).toEqual(1);});runs(function(){this.foo++;varbar=0bar++;expect(this.foo).toEqual(2);expect(bar).toEqual(1);});});
it('should be a test',function(){runs(function(){this.foo=0;varthat=this;setTimeout(function(){that.foo++;},250);});runs(function(){expect(this.foo).toEqual(0);});waits(500);runs(function(){expect(this.foo).toEqual(1);});});
describe('waitsFor Test',function(){it('after 2sec, it will be true',function(){variWillBeTrue=false;setTimeout(function(){iWillBeTrue=true;},2000);waitsFor(function(){returniWillBeTrue;},"maybe i will never be true",10000);runs(function(){expect(iWillBeTrue).toEqual(true);});});});
运行一下:
12345
waitsFor Test
after 2sec, it will be trueFinished in 2.013 seconds
1 test, 1 assertion, 0 failures
我们去掉setTimeout,那么应该iWillBeTrue将永远为false,重新运行:
12345678910111213
waitsFor Test
after 2sec, it will be trueFailures:
1) after 2sec, it will be trueMessage:
timeout: timed out after 10000 msec waiting for maybe i will never be trueStacktrace:
undefined
Finished in 10.921 seconds
1 test, 1 assertion, 1 failure