Mocha+Chai???????????????????
????????? ???????[ 2017/1/17 10:06:46 ] ????????Mocha ???????
?????????????????????????? ????£?
???????????????Node?????????????????????????????????????????????Χ?Щ???????????н?????????????????????????????????????????????е?????????????в?????????????????????????
???????????????????????????????????????????????壬????????????????????Mocha??chai Assert?????????????????????????????????е????Hour???????
????????????????о??????????????????е?????????
????????????????????????????????????????????????????£????????????????????????????????????????????
????????????????????????????????????
?????. ???????
??????????????????
????TDD??Test-Driven Development???????????????????????????
????BDD??Behavior Driven Development??????????????????????????
????????TDD??BDD?????????? ????TDD??BDD??DDD???Щ???? ??
???????????????????? ???????????????????? 5 ?????? ??
????mocha????????BDD??
??????. Mocha????
??????Node.js?У?????????е???????????? mocha + chai ??mocha????????????chai????????????????”???”??
??????????????У? jasmine ?? should.js ?? chai ?? assert ??????????????????????????????????chai??????assert?????????????????????
????Mocha????????У?
??????????????????????Promise??
??????????????coverage??????棻
??????????ò????????????????
????… …
??????????????? Mocha + chai(assert???) ??
??????????£?
????npm install mocha -g
????npm install mocha
????npm install chai
??????Mocha?????????
????mocha [debug] [options] [files]
?????磺
????mocha --recursive test/
??????. Mocha????????????????
????Mocha????????????????
????describe(moduleName?? function)
????describe????????????????????????????
????describe('????????????'?? function() {
????// ....
????});
????it(info?? function)
????info???????????????it???????????????????
????describe('?????????????????д???????????'?? function() {
????// ....
????});
????assert.equal(exp1?? exp2)
????mocha?????????ж?exp1??????exp2??
??????. Mocha????????????
????done
???????it??????????done??
????done??????????????????????????????
???????????mocha v3.x?汾??Promise??????????? done ??????????????????Promise?????????done??????
describe('User'?? function() {
describe('#save()'?? function() {
it('should save without error'?? function(done) {
var user = new User('Luna');
user.save(done);
});
});
});
??????. Test Hooks??????
????before() ?? after() ?? beforeEach() ?? afterEach() ?????BDD???????????????????test???????
????Test Hooks?????????????
????beforeEach?????describe?μ???????case??Ч??
????before??after??????????????????
????????describe?μ????????before??beforeEach??afterEach??after??
?????????it?ж??before????????????????Χ??describe??before?????????????
describe('hooks'?? function() {
before(function() {
// runs before all tests in this block
});
after(function() {
// runs after all tests in this block
});
beforeEach(function() {
// runs before each test in this block
});
afterEach(function() {
// runs after each test in this block
});
// test cases
});
????Hooks??????д????
????beforeEach(function() {
????});
????beforeEach(function nameFun() {
????});
????beforeEach("some description"?? function() {
????});
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11