Debian Codegraph @

pretender/test/handler_test.js

raw
1 var describe = QUnit.module;
2 var it = QUnit.test;
3
4 describe('pretender adding a handler', function(config) {
5 config.beforeEach(function() {
6 this.pretender = new Pretender();
7 });
8
9 config.afterEach(function() {
10 this.pretender.shutdown();
11 });
12
13 it('a handler is returned', function(assert) {
14 var handler = this.pretender.get('/some/path', function() {});
15 assert.ok(handler);
16 });
17
18 it('.get registers a handler for GET', function(assert) {
19 var wasCalled;
20
21 this.pretender.get('/some/path', function() {
22 wasCalled = true;
23 });
24
25 $.ajax({ url: '/some/path' });
26 assert.ok(wasCalled);
27 });
28
29 it('.post registers a handler for POST', function(assert) {
30 var wasCalled;
31
32 this.pretender.post('/some/path', function() {
33 wasCalled = true;
34 });
35
36 $.ajax({ url: '/some/path', method: 'post' });
37 assert.ok(wasCalled);
38 });
39
40 it('.patch registers a handler for PATCH', function(assert) {
41 var wasCalled;
42
43 this.pretender.patch('/some/path', function() {
44 wasCalled = true;
45 });
46
47 $.ajax({ url: '/some/path', method: 'patch' });
48 assert.ok(wasCalled);
49 });
50
51 it('.delete registers a handler for DELETE', function(assert) {
52 var wasCalled;
53
54 this.pretender.delete('/some/path', function() {
55 wasCalled = true;
56 });
57
58 $.ajax({ url: '/some/path', method: 'delete' });
59 assert.ok(wasCalled);
60 });
61
62 it('.options registers a handler for OPTIONS', function(assert) {
63 var wasCalled;
64
65 this.pretender.options('/some/path', function() {
66 wasCalled = true;
67 });
68
69 $.ajax({ url: '/some/path', method: 'options' });
70 assert.ok(wasCalled);
71 });
72
73 it('.put registers a handler for PUT', function(assert) {
74 var wasCalled;
75
76 this.pretender.put('/some/path', function() {
77 wasCalled = true;
78 });
79
80 $.ajax({ url: '/some/path', method: 'put' });
81 assert.ok(wasCalled);
82 });
83
84 it('.head registers a handler for HEAD', function(assert) {
85 var wasCalled;
86
87 this.pretender.head('/some/path', function() {
88 wasCalled = true;
89 });
90
91 $.ajax({ url: '/some/path', method: 'head' });
92 assert.ok(wasCalled);
93 });
94 });