forked from js-data/js-data-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
karma.start.js
81 lines (72 loc) · 2.56 KB
/
karma.start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Setup global test variables
var adapter, User, Post, datastore, DSUtils, queryTransform, p1, p2, p3, p4, p5;
// Helper globals
var fail = function (msg) {
if (msg instanceof Error) {
console.log(msg.stack);
} else {
assert.equal('should not reach this!: ' + msg, 'failure');
}
};
var TYPES_EXCEPT_STRING = [123, 123.123, null, undefined, {}, [], true, false, function () {
}];
var TYPES_EXCEPT_STRING_OR_ARRAY = [123, 123.123, null, undefined, {}, true, false, function () {
}];
var TYPES_EXCEPT_STRING_OR_OBJECT = [123, 123.123, null, undefined, [], true, false, function () {
}];
var TYPES_EXCEPT_STRING_OR_NUMBER_OBJECT = [null, undefined, [], true, false, function () {
}];
var TYPES_EXCEPT_ARRAY = ['string', 123, 123.123, null, undefined, {}, true, false, function () {
}];
var TYPES_EXCEPT_STRING_OR_NUMBER = [null, undefined, {}, [], true, false, function () {
}];
var TYPES_EXCEPT_STRING_OR_ARRAY_OR_NUMBER = [null, undefined, {}, true, false, function () {
}];
var TYPES_EXCEPT_NUMBER = ['string', null, undefined, {}, [], true, false, function () {
}];
var TYPES_EXCEPT_OBJECT = ['string', 123, 123.123, null, undefined, true, false, function () {
}];
var TYPES_EXCEPT_BOOLEAN = ['string', 123, 123.123, null, undefined, {}, [], function () {
}];
var TYPES_EXCEPT_FUNCTION = ['string', 123, 123.123, null, undefined, {}, [], true, false];
// Setup before each test
beforeEach(function () {
var JSData;
if (!window && typeof module !== 'undefined' && module.exports) {
JSData = require('js-data');
} else {
JSData = window.JSData;
}
queryTransform = function (resourceName, query) {
queryTransform.callCount += 1;
return query;
};
DSUtils = JSData.DSUtils;
datastore = new JSData.DS();
User = datastore.defineResource('user');
Post = datastore.defineResource({
name: 'posts',
basePath: 'api'
});
adapter = new DSHalAdapter({
queryTransform: queryTransform
});
datastore.registerAdapter('http', adapter, { default: true });
queryTransform.callCount = 0;
p1 = { author: 'John', age: 30, id: 5 };
p2 = { author: 'Sally', age: 31, id: 6 };
p3 = { author: 'Mike', age: 32, id: 7 };
p4 = { author: 'Adam', age: 33, id: 8 };
p5 = { author: 'Adam', age: 33, id: 9 };
this.xhr = sinon.useFakeXMLHttpRequest();
// Create an array to store requests
var requests = this.requests = [];
// Keep references to created requests
this.xhr.onCreate = function (xhr) {
requests.push(xhr);
};
});
afterEach(function () {
// Restore the global timer functions to their native implementations
this.xhr.restore();
});