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)
复制代码