forked from JamieMason/Jasmine-Matchers
/
toBeJsendString.spec.js
53 lines (50 loc) · 1.65 KB
/
toBeJsendString.spec.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
var jsendSamples = require('./lib/jsendSampleData');
var validJsend = jsendSamples.valid;
var invalidJsend = jsendSamples.invalid;
function stringifyIfJson(obj) {
try {
return JSON.stringify(obj);
} catch (err) {
return String(obj);
}
}
// spec
describe('toBeJsendString', function () {
describe('when invoked', function () {
describe('when subject IS a JSEND String', function () {
it('should confirm', function () {
validJsend.success.forEach(function (jsend) {
expect(JSON.stringify(jsend)).toBeJsendString();
});
validJsend.fail.forEach(function (jsend) {
expect(JSON.stringify(jsend)).toBeJsendString();
});
validJsend.error.forEach(function (jsend) {
expect(JSON.stringify(jsend)).toBeJsendString();
});
});
});
describe('when subject is NOT a JSEND String', function () {
it('should deny', function () {
validJsend.success.forEach(function (jsend) {
expect(jsend).not.toBeJsendString();
});
validJsend.fail.forEach(function (jsend) {
expect(jsend).not.toBeJsendString();
});
validJsend.error.forEach(function (jsend) {
expect(jsend).not.toBeJsendString();
});
invalidJsend.success.forEach(function (jsend) {
expect(stringifyIfJson(jsend)).not.toBeJsendString();
});
invalidJsend.fail.forEach(function (jsend) {
expect(stringifyIfJson(jsend)).not.toBeJsendString();
});
invalidJsend.error.forEach(function (jsend) {
expect(stringifyIfJson(jsend)).not.toBeJsendString();
});
});
});
});
});