-
Notifications
You must be signed in to change notification settings - Fork 26
/
karma.start.js
72 lines (63 loc) · 1.96 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
/* global JSData:true, JSDataHttp:true, sinon:true, chai:true */
before(function () {
var Test = this
Test.TEST_FETCH = false
Test.fail = function (msg) {
if (msg instanceof Error) {
console.log(msg.stack)
} else {
Test.assert.equal('should not reach this!: ' + msg, 'failure')
}
}
Test.assert = chai.assert
Test.assert.objectsEqual = function (a, b, m) {
Test.assert.deepEqual(JSON.parse(JSON.stringify(a)), JSON.parse(JSON.stringify(b)), m || (JSON.stringify(a) + ' should be equal to ' + JSON.stringify(b)))
}
Test.sinon = sinon
Test.JSData = JSData
Test.addAction = JSDataHttp.addAction
Test.addActions = JSDataHttp.addActions
Test.HttpAdapter = JSDataHttp.HttpAdapter
Test.store = new JSData.DataStore()
Test.adapter = new Test.HttpAdapter()
Test.store.registerAdapter('http', Test.adapter, { default: true })
Test.User = new JSData.Mapper({
name: 'user'
})
Test.Post = new JSData.Mapper({
name: 'post',
endpoint: 'posts',
basePath: 'api'
})
Test.User.registerAdapter('http', Test.adapter, { default: true })
Test.Post.registerAdapter('http', Test.adapter, { default: true })
console.log('Testing against js-data ' + JSData.version.full)
})
beforeEach(function () {
var Test = this
Test.p1 = { author: 'John', age: 30, id: 5 }
Test.p2 = { author: 'Sally', age: 31, id: 6 }
Test.p3 = { author: 'Mike', age: 32, id: 7 }
Test.p4 = { author: 'Adam', age: 33, id: 8 }
Test.p5 = { author: 'Adam', age: 33, id: 9 }
try {
Test.xhr = Test.sinon.useFakeXMLHttpRequest()
// Create an array to store requests
Test.requests = []
// Keep references to created requests
Test.xhr.onCreate = function (xhr) {
Test.requests.push(xhr)
}
} catch (err) {
console.error(err)
}
})
afterEach(function () {
var Test = this
// Restore the global timer functions to their native implementations
try {
Test.xhr.restore()
} catch (err) {
console.error(err)
}
})