OSDN Git Service

Regular updates
[twpd/master.git] / mocha-tdd.md
1 ---
2 title: Mocha.js TDD interface
3 category: JavaScript libraries
4 ---
5
6 ### TDD
7
8     mocha.setup('tdd');
9
10     suite('something', function() {
11       setup(function() {
12       });
13
14       test('should work', function() {
15       });
16
17       teardown(function() {
18       });
19     });
20
21 ### Async
22
23     test('should save', function(done) {
24       var user = new User();
25       user.save(function(err) {
26         if (err) throw err;
27         done();
28       });
29     });
30
31 ### Chai: Expect
32
33     var expect = chai.expect;
34
35     expect(foo).to.be.a('string');
36     expect(foo).to.equal('bar');
37     expect(foo).to.have.length(3);
38     expect(tea).to.have.property('flavors').with.length(3);
39
40 ### See also
41
42  * [Mocha BDD](mocha.html)
43  * [Mocha HTML](mocha-html.html)
44  * [Chai](chai.html)
45  * [Sinon](sinon.html)
46  * [Sinon Chai](sinon-chai.html)