var assert = require('assert')
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
assert.equal(-1, [1, 2, 3].indexOf(4))
})
})
複製代碼
var should = require('should');
var add = require('../lib/add');
describe('大數相加add方法', function () {
it('字符串"42329"加上字符串"21532"等於"63861"', function () {
add('9987', '987')
.should.equal('10974')
})
it('"843529812342341234"加上"236124361425345435"等於"1079654173767686669"', function () {
add('843529812342341234', '236124361425345435')
.should.equal('1079654173767686669')
})
})
複製代碼
//選全局安裝karma-cli
npm install -g karma-cli
//而後在你的項目裏安裝karma
npm i karma -D
//安裝一些插件
npm i npm install karma-jasmine karma-chrome-launcher jasmine-core --save-dev
複製代碼
接下里初始化karma
在上面項目的根目錄下使用下面命令
karma init
複製代碼
按照以下配置選擇配置項
1. Which testing framework do you want to use ? (mocha)
2. Do you want to use Require.js ? (no)
3. Do you want to capture any browsers automatically ? (Chrome)
4. What is the location of your source and test files ? (https://cdn.bootcss.com/jquery/2.2.4/jquery.js, node_modules/should/should.js, test/**.js)
5. Should any of the files included by the previous patterns be excluded ? ()
6. Do you want Karma to watch all the files and run the tests on change ? (yes)
複製代碼