Debian Codegraph @

pretender/test/creation_test.js

raw
1 var pretender;
2 var describe = QUnit.module;
3 var it = QUnit.test;
4
5 describe('pretender creation', function(config) {
6 config.afterEach(function() {
7 if (pretender) {
8 pretender.shutdown();
9 }
10 pretender = null;
11 });
12
13 it('a mapping function is optional', function(assert) {
14 try {
15 pretender = new Pretender();
16 } catch (e) {
17 assert.ok(false);
18 }
19
20 assert.ok(true, 'does not raise');
21 });
22
23 it('many maps can be passed on creation', function(assert) {
24 var aWasCalled = false;
25 var bWasCalled = false;
26
27 var mapA = function() {
28 this.get('/some/path', function() {
29 aWasCalled = true;
30 });
31 };
32
33 var mapB = function() {
34 this.get('/other/path', function() {
35 bWasCalled = true;
36 });
37 };
38
39 pretender = new Pretender(mapA, mapB);
40
41 $.ajax({ url: '/some/path' });
42 $.ajax({ url: '/other/path' });
43
44 assert.ok(aWasCalled);
45 assert.ok(bWasCalled);
46 });
47
48 it('an error is thrown when a request handler is missing', function(assert) {
49 assert.throws(function() {
50 pretender = new Pretender();
51 pretender.get('/path', undefined);
52 }, 'The function you tried passing to Pretender to handle GET /path is undefined or missing.');
53 });
54 });