forked from github-tools/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbacks.js
More file actions
49 lines (43 loc) · 1.16 KB
/
callbacks.js
File metadata and controls
49 lines (43 loc) · 1.16 KB
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
import expect from 'must';
const STANDARD_DELAY = 200; // 200ms between nested calls to the API so things settle
export function assertSuccessful(done, cb) {
return function successCallback(err, res, xhr) {
try {
expect(err).not.to.exist(err ? (err.response ? err.response.data : err) : 'No error');
expect(res).to.exist();
if (cb) {
setTimeout(function delay() {
cb(err, res, xhr);
}, STANDARD_DELAY);
} else {
done();
}
} catch (e) {
done(e);
}
};
}
export function assertFailure(done, cb) {
return function failureCallback(err) {
try {
expect(err).to.exist();
expect(err).to.have.ownProperty('path');
expect(err.request).to.exist();
if (cb) {
setTimeout(function delay() {
cb(err);
}, STANDARD_DELAY);
} else {
done();
}
} catch (e) {
done(e);
}
};
}
export function assertArray(done) {
return assertSuccessful(done, function isArray(err, result) {
expect(result).to.be.an.array();
done();
});
}