??????д?????javascript???????(????)???????????????????????????????????????????????????????
????????????
????TDD??BDD

????TDD???????????????BDD?????????????
????????
????node???????????assert?????chai.js????????????
??????????
??????????????????????????Mocha
?????????Mocha?????????????Javascript????????
????Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser?? making asynchronous testing simple and fun. Mocha tests run serially?? allowing for flexible and accurate reporting?? while mapping uncaught exceptions to the correct test cases.
?????????
???????

?????????????
????$ npm install --global mocha
???????????????????а??
????$ npm install --save-dev mocha
???????????
??????????test????У???test????????????test.js??????????????
var assert = require("assert");
describe('Array'??function(){
describe('#indexOf()'??function(){
it('should return -1 when the value is not present'??function(){
assert.equal(-1??[1??2??3].indexOf(4));
})
})
})
???????assert?????????????????????ж??????????assert.equal???ж?????????????????????
????assert????????????????
assert.fail(actual?? expected?? message?? operator)
assert.ok(value?? [message])
assert.equal(actual?? expected?? [message])
assert.notEqual(actual?? expected?? [message])
assert.deepEqual(actual?? expected?? [message])
assert.notDeepEqual(actual?? expected?? [message])
assert.strictEqual(actual?? expected?? [message])
assert.notStrictEqual(actual?? expected?? [message])
assert.throws(block?? [error]?? [message])
assert.doesNotThrow(block?? [error]?? [message])
assert.ifError(value)
???????????????????????describe(' '??function(){})???????????????describe??????????????????describe??it????BDD???????????????????????о???????suite??test????TDD
???????в???
????????????????????

????mocha test.js
?????????????????????????????????????????
????Array
????#indexOf()
????should return -1 when the value is not present
????1 passing (9ms)
?????????????
????should.js - BDD style shown throughout these docs
????expect.js - expect() style assertions
????chai - expect()?? assert() and should-style assertions
????better-assert - C-style self-documenting assert()
????unexpected - “the extensible BDD assertion toolkit”
????chai???expect()??assert()??should???????????????chai????????????????
????????expet
var expect = require('chai').expect;
describe('arrays'?? function() {
var a;
beforeEach(function() {
a = [ 1?? 2?? 3?? 4 ];
});
it('you should be able to determine the location of an item in an array'?? function() {
expect(arraysAnswers.indexOf(a?? 3)).to.eql(2);
expect(arraysAnswers.indexOf(a?? 5)).to.eql(-1);});
}