]> git.cworth.org Git - obsolete/notmuch-web/blob - node_modules/express/node_modules/qs/support/should/test/should.test.js
Install the "express" node module via npm
[obsolete/notmuch-web] / node_modules / express / node_modules / qs / support / should / test / should.test.js
1
2 /**
3  * Module dependencies.
4  */
5
6 var should = require('should');
7
8 function err(fn, msg) {
9   try {
10     fn();
11     should.fail('expected an error');
12   } catch (err) {
13     should.equal(msg, err.message);
14   }
15 }
16
17 module.exports = {
18   'test .version': function(){
19     should.version.should.match(/^\d+\.\d+\.\d+$/);
20   },
21
22   'test double require': function(){
23     require('should').should.equal(should);
24   },
25
26   'test assertion': function(){
27     'test'.should.be.a.string;
28     should.equal('foo', 'foo');
29   },
30   
31   'test true': function(){
32     true.should.be.true;
33     false.should.not.be.true;
34     (1).should.not.be.true;
35     
36     err(function(){
37       'test'.should.be.true;
38     }, "expected 'test' to be true")
39   },
40   
41   'test ok': function(){
42     true.should.be.ok;
43     false.should.not.be.ok;
44     (1).should.be.ok;
45     (0).should.not.be.ok;
46     
47     err(function(){
48       ''.should.be.ok;
49     }, "expected '' to be truthy");
50     
51     err(function(){
52       'test'.should.not.be.ok;
53     }, "expected 'test' to be falsey");
54   },
55   
56   'test false': function(){
57     false.should.be.false;
58     true.should.not.be.false;
59     (0).should.not.be.false;
60     
61     err(function(){
62       ''.should.be.false;
63     }, "expected '' to be false")
64   },
65   
66   'test arguments': function(){
67     var args = (function(){ return arguments; })(1,2,3);
68     args.should.be.arguments;
69     [].should.not.be.arguments;
70   },
71   
72   'test .equal()': function(){
73     var foo;
74     should.equal(undefined, foo);
75   },
76   
77   'test typeof': function(){
78     'test'.should.be.a('string');
79
80     err(function(){
81       'test'.should.not.be.a('string');
82     }, "expected 'test' not to be a string");
83     
84     (5).should.be.a('number');
85
86     err(function(){
87       (5).should.not.be.a('number');
88     }, "expected 5 not to be a number");
89   },
90   
91   'test instanceof': function(){
92     function Foo(){}
93     new Foo().should.be.an.instanceof(Foo);
94
95     err(function(){
96       (3).should.an.instanceof(Foo);
97     }, "expected 3 to be an instance of Foo");
98   },
99   
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);
105     
106     err(function(){
107       (5).should.not.be.within(4,6);
108     }, "expected 5 to not be within 4..6");
109     
110     err(function(){
111       (10).should.be.within(50,100);
112     }, "expected 10 to be within 50..100");
113   },
114   
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);
120
121     err(function(){
122       (5).should.be.above(6);
123     }, "expected 5 to be above 6");
124     
125     err(function(){
126       (10).should.not.be.above(6);
127     }, "expected 10 to be below 6");
128   },
129   
130   'test match(regexp)': function(){
131     'foobar'.should.match(/^foo/)
132     'foobar'.should.not.match(/^bar/)
133     
134     err(function(){
135       'foobar'.should.match(/^bar/i)
136     }, "expected 'foobar' to match /^bar/i");
137     
138     err(function(){
139       'foobar'.should.not.match(/^foo/i)
140     }, "expected 'foobar' not to match /^foo/i");
141   },
142   
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);
147     
148     err(function(){
149       (4).should.have.length(3);
150     }, 'expected 4 to have a property \'length\'');
151     
152     err(function(){
153       'asd'.should.not.have.length(3);
154     }, "expected 'asd' to not have a length of 3");
155   },
156   
157   'test eql(val)': function(){
158     'test'.should.eql('test');
159     ({ foo: 'bar' }).should.eql({ foo: 'bar' });
160     (1).should.eql(1);
161     '4'.should.eql(4);
162     
163     err(function(){
164       (4).should.eql(3);
165     }, 'expected 4 to equal 3');
166   },
167   
168   'test equal(val)': function(){
169     'test'.should.equal('test');
170     (1).should.equal(1);
171     
172     err(function(){
173       (4).should.equal(3);
174     }, 'expected 4 to equal 3');
175     
176     err(function(){
177       '4'.should.equal(4);
178     }, "expected '4' to equal 4");
179   },
180   
181   'test empty': function(){
182     ''.should.be.empty;
183     [].should.be.empty;
184     ({ length: 0 }).should.be.empty;
185     
186     err(function(){
187       ({}).should.be.empty;
188     }, 'expected {} to have a property \'length\'');
189     
190     err(function(){
191       'asd'.should.be.empty;
192     }, "expected 'asd' to be empty");
193     
194     err(function(){
195       ''.should.not.be.empty;
196     }, "expected '' not to be empty");
197   },
198   
199   'test property(name)': function(){
200     'test'.should.have.property('length');
201     (4).should.not.have.property('length');
202     
203     err(function(){
204       'asd'.should.have.property('foo');
205     }, "expected 'asd' to have a property 'foo'");
206   },
207   
208   'test property(name, val)': function(){
209     'test'.should.have.property('length', 4);
210     'asd'.should.have.property('constructor', String);
211     
212     err(function(){
213       'asd'.should.have.property('length', 4);
214     }, "expected 'asd' to have a property 'length' of 4, but got 3");
215     
216     err(function(){
217       'asd'.should.not.have.property('length', 3);
218     }, "expected 'asd' to not have a property 'length' of 3");
219     
220     err(function(){
221       'asd'.should.not.have.property('foo', 3);
222     }, "'asd' has no property 'foo'");
223     
224     err(function(){
225       'asd'.should.have.property('constructor', Number);
226     }, "expected 'asd' to have a property 'constructor' of [Function: Number], but got [Function: String]");
227   },
228   
229   'test ownProperty(name)': function(){
230     'test'.should.have.ownProperty('length');
231     'test'.should.haveOwnProperty('length');
232     ({ length: 12 }).should.have.ownProperty('length');
233     
234     err(function(){
235       ({ length: 12 }).should.not.have.ownProperty('length');
236     }, "expected { length: 12 } to not have own property 'length'");
237   },
238   
239   'test string()': function(){
240     'foobar'.should.include.string('bar');
241     'foobar'.should.include.string('foo');
242     'foobar'.should.not.include.string('baz');
243
244     err(function(){
245       (3).should.include.string('baz');
246     }, "expected 3 to be a string");
247     
248     err(function(){
249       'foobar'.should.include.string('baz');
250     }, "expected 'foobar' to include 'baz'");
251     
252     err(function(){
253       'foobar'.should.not.include.string('bar');
254     }, "expected 'foobar' to not include 'bar'");
255   },
256   
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);
264
265     err(function(){
266       ['foo'].should.contain('bar');
267     }, "expected [ 'foo' ] to contain 'bar'");
268     
269     err(function(){
270       ['bar', 'foo'].should.not.contain('foo');
271     }, "expected [ 'bar', 'foo' ] to not contain 'foo'");
272   },
273   
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');
281
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']);
287
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');
293
294     err(function(){
295       ({ foo: 1 }).should.have.keys();
296     }, "keys required");
297     
298     err(function(){
299       ({ foo: 1 }).should.have.keys([]);
300     }, "keys required");
301     
302     err(function(){
303       ({ foo: 1 }).should.not.have.keys([]);
304     }, "keys required");
305     
306     err(function(){
307       ({ foo: 1 }).should.include.keys([]);
308     }, "keys required");
309
310     err(function(){
311       ({ foo: 1 }).should.have.keys(['bar']);
312     }, "expected { foo: 1 } to have key 'bar'");
313     
314     err(function(){
315       ({ foo: 1 }).should.have.keys(['bar', 'baz']);
316     }, "expected { foo: 1 } to have keys 'bar', and 'baz'");
317     
318     err(function(){
319       ({ foo: 1 }).should.have.keys(['foo', 'bar', 'baz']);
320     }, "expected { foo: 1 } to have keys 'foo', 'bar', and 'baz'");
321
322     err(function(){
323       ({ foo: 1 }).should.not.have.keys(['foo']);
324     }, "expected { foo: 1 } to not have key 'foo'");
325     
326     err(function(){
327       ({ foo: 1 }).should.not.have.keys(['foo']);
328     }, "expected { foo: 1 } to not have key 'foo'");
329     
330     err(function(){
331       ({ foo: 1, bar: 2 }).should.not.have.keys(['foo', 'bar']);
332     }, "expected { foo: 1, bar: 2 } to not have keys 'foo', and 'bar'");
333     
334     err(function(){
335       ({ foo: 1 }).should.not.include.keys(['foo']);
336     }, "expected { foo: 1 } to not include key 'foo'");
337     
338     err(function(){
339       ({ foo: 1 }).should.include.keys('foo', 'bar');
340     }, "expected { foo: 1 } to include keys 'foo', and 'bar'");
341   },
342   
343   'test respondTo(method)': function(){
344     'test'.should.respondTo('toString');
345     'test'.should.not.respondTo('toBuffer');
346   },
347   
348   'test chaining': function(){
349     var user = { name: 'tj', pets: ['tobi', 'loki', 'jane', 'bandit'] };
350     user.should.have.property('pets').with.lengthOf(4);
351  
352     err(function(){
353       user.should.have.property('pets').with.lengthOf(5);
354     }, "expected [ 'tobi', 'loki', 'jane', 'bandit' ] to have a length of 5 but got 4");
355  
356     user.should.be.a('object').and.have.property('name', 'tj');
357   }
358 };