6 var should = require('should');
8 function err(fn, msg) {
11 should.fail('expected an error');
13 should.equal(msg, err.message);
18 'test .version': function(){
19 should.version.should.match(/^\d+\.\d+\.\d+$/);
22 'test double require': function(){
23 require('should').should.equal(should);
26 'test assertion': function(){
27 'test'.should.be.a.string;
28 should.equal('foo', 'foo');
31 'test true': function(){
33 false.should.not.be.true;
34 (1).should.not.be.true;
37 'test'.should.be.true;
38 }, "expected 'test' to be true")
41 'test ok': function(){
43 false.should.not.be.ok;
49 }, "expected '' to be truthy");
52 'test'.should.not.be.ok;
53 }, "expected 'test' to be falsey");
56 'test false': function(){
57 false.should.be.false;
58 true.should.not.be.false;
59 (0).should.not.be.false;
63 }, "expected '' to be false")
66 'test arguments': function(){
67 var args = (function(){ return arguments; })(1,2,3);
68 args.should.be.arguments;
69 [].should.not.be.arguments;
72 'test .equal()': function(){
74 should.equal(undefined, foo);
77 'test typeof': function(){
78 'test'.should.be.a('string');
81 'test'.should.not.be.a('string');
82 }, "expected 'test' not to be a string");
84 (5).should.be.a('number');
87 (5).should.not.be.a('number');
88 }, "expected 5 not to be a number");
91 'test instanceof': function(){
93 new Foo().should.be.an.instanceof(Foo);
96 (3).should.an.instanceof(Foo);
97 }, "expected 3 to be an instance of Foo");
100 'test within(start, finish)': function(){
101 (5).should.be.within(5, 10);
102 (5).should.be.within(3,6);
103 (5).should.be.within(3,5);
104 (5).should.not.be.within(1,3);
107 (5).should.not.be.within(4,6);
108 }, "expected 5 to not be within 4..6");
111 (10).should.be.within(50,100);
112 }, "expected 10 to be within 50..100");
115 'test above(n)': function(){
116 (5).should.be.above(2);
117 (5).should.be.greaterThan(2);
118 (5).should.not.be.above(5);
119 (5).should.not.be.above(6);
122 (5).should.be.above(6);
123 }, "expected 5 to be above 6");
126 (10).should.not.be.above(6);
127 }, "expected 10 to be below 6");
130 'test match(regexp)': function(){
131 'foobar'.should.match(/^foo/)
132 'foobar'.should.not.match(/^bar/)
135 'foobar'.should.match(/^bar/i)
136 }, "expected 'foobar' to match /^bar/i");
139 'foobar'.should.not.match(/^foo/i)
140 }, "expected 'foobar' not to match /^foo/i");
143 'test length(n)': function(){
144 'test'.should.have.length(4);
145 'test'.should.not.have.length(3);
146 [1,2,3].should.have.length(3);
149 (4).should.have.length(3);
150 }, 'expected 4 to have a property \'length\'');
153 'asd'.should.not.have.length(3);
154 }, "expected 'asd' to not have a length of 3");
157 'test eql(val)': function(){
158 'test'.should.eql('test');
159 ({ foo: 'bar' }).should.eql({ foo: 'bar' });
165 }, 'expected 4 to equal 3');
168 'test equal(val)': function(){
169 'test'.should.equal('test');
174 }, 'expected 4 to equal 3');
178 }, "expected '4' to equal 4");
181 'test empty': function(){
184 ({ length: 0 }).should.be.empty;
187 ({}).should.be.empty;
188 }, 'expected {} to have a property \'length\'');
191 'asd'.should.be.empty;
192 }, "expected 'asd' to be empty");
195 ''.should.not.be.empty;
196 }, "expected '' not to be empty");
199 'test property(name)': function(){
200 'test'.should.have.property('length');
201 (4).should.not.have.property('length');
204 'asd'.should.have.property('foo');
205 }, "expected 'asd' to have a property 'foo'");
208 'test property(name, val)': function(){
209 'test'.should.have.property('length', 4);
210 'asd'.should.have.property('constructor', String);
213 'asd'.should.have.property('length', 4);
214 }, "expected 'asd' to have a property 'length' of 4, but got 3");
217 'asd'.should.not.have.property('length', 3);
218 }, "expected 'asd' to not have a property 'length' of 3");
221 'asd'.should.not.have.property('foo', 3);
222 }, "'asd' has no property 'foo'");
225 'asd'.should.have.property('constructor', Number);
226 }, "expected 'asd' to have a property 'constructor' of [Function: Number], but got [Function: String]");
229 'test ownProperty(name)': function(){
230 'test'.should.have.ownProperty('length');
231 'test'.should.haveOwnProperty('length');
232 ({ length: 12 }).should.have.ownProperty('length');
235 ({ length: 12 }).should.not.have.ownProperty('length');
236 }, "expected { length: 12 } to not have own property 'length'");
239 'test string()': function(){
240 'foobar'.should.include.string('bar');
241 'foobar'.should.include.string('foo');
242 'foobar'.should.not.include.string('baz');
245 (3).should.include.string('baz');
246 }, "expected 3 to be a string");
249 'foobar'.should.include.string('baz');
250 }, "expected 'foobar' to include 'baz'");
253 'foobar'.should.not.include.string('bar');
254 }, "expected 'foobar' to not include 'bar'");
257 'test contain()': function(){
258 ['foo', 'bar'].should.contain('foo');
259 ['foo', 'bar'].should.contain('foo');
260 ['foo', 'bar'].should.contain('bar');
261 [1,2].should.contain(1);
262 ['foo', 'bar'].should.not.contain('baz');
263 ['foo', 'bar'].should.not.contain(1);
266 ['foo'].should.contain('bar');
267 }, "expected [ 'foo' ] to contain 'bar'");
270 ['bar', 'foo'].should.not.contain('foo');
271 }, "expected [ 'bar', 'foo' ] to not contain 'foo'");
274 'test keys(array)': function(){
275 ({ foo: 1 }).should.have.keys(['foo']);
276 ({ foo: 1, bar: 2 }).should.have.keys(['foo', 'bar']);
277 ({ foo: 1, bar: 2 }).should.have.keys('foo', 'bar');
278 ({ foo: 1, bar: 2, baz: 3 }).should.include.keys('foo', 'bar');
279 ({ foo: 1, bar: 2, baz: 3 }).should.include.keys('bar', 'foo');
280 ({ foo: 1, bar: 2, baz: 3 }).should.include.keys('baz');
282 ({ foo: 1, bar: 2 }).should.include.keys('foo');
283 ({ foo: 1, bar: 2 }).should.include.keys('bar', 'foo');
284 ({ foo: 1, bar: 2 }).should.include.keys(['foo']);
285 ({ foo: 1, bar: 2 }).should.include.keys(['bar']);
286 ({ foo: 1, bar: 2 }).should.include.keys(['bar', 'foo']);
288 ({ foo: 1, bar: 2 }).should.not.have.keys('baz');
289 ({ foo: 1, bar: 2 }).should.not.have.keys('foo', 'baz');
290 ({ foo: 1, bar: 2 }).should.not.include.keys('baz');
291 ({ foo: 1, bar: 2 }).should.not.include.keys('foo', 'baz');
292 ({ foo: 1, bar: 2 }).should.not.include.keys('baz', 'foo');
295 ({ foo: 1 }).should.have.keys();
299 ({ foo: 1 }).should.have.keys([]);
303 ({ foo: 1 }).should.not.have.keys([]);
307 ({ foo: 1 }).should.include.keys([]);
311 ({ foo: 1 }).should.have.keys(['bar']);
312 }, "expected { foo: 1 } to have key 'bar'");
315 ({ foo: 1 }).should.have.keys(['bar', 'baz']);
316 }, "expected { foo: 1 } to have keys 'bar', and 'baz'");
319 ({ foo: 1 }).should.have.keys(['foo', 'bar', 'baz']);
320 }, "expected { foo: 1 } to have keys 'foo', 'bar', and 'baz'");
323 ({ foo: 1 }).should.not.have.keys(['foo']);
324 }, "expected { foo: 1 } to not have key 'foo'");
327 ({ foo: 1 }).should.not.have.keys(['foo']);
328 }, "expected { foo: 1 } to not have key 'foo'");
331 ({ foo: 1, bar: 2 }).should.not.have.keys(['foo', 'bar']);
332 }, "expected { foo: 1, bar: 2 } to not have keys 'foo', and 'bar'");
335 ({ foo: 1 }).should.not.include.keys(['foo']);
336 }, "expected { foo: 1 } to not include key 'foo'");
339 ({ foo: 1 }).should.include.keys('foo', 'bar');
340 }, "expected { foo: 1 } to include keys 'foo', and 'bar'");
343 'test respondTo(method)': function(){
344 'test'.should.respondTo('toString');
345 'test'.should.not.respondTo('toBuffer');
348 'test chaining': function(){
349 var user = { name: 'tj', pets: ['tobi', 'loki', 'jane', 'bandit'] };
350 user.should.have.property('pets').with.lengthOf(4);
353 user.should.have.property('pets').with.lengthOf(5);
354 }, "expected [ 'tobi', 'loki', 'jane', 'bandit' ] to have a length of 5 but got 4");
356 user.should.be.a('object').and.have.property('name', 'tj');