-
Notifications
You must be signed in to change notification settings - Fork 1
/
httpBodyEquals.js
47 lines (29 loc) · 1.02 KB
/
httpBodyEquals.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
/*
* httpBodyEquals.js: Convenience for checking body equality without serializing
*
* (C) 2012 Crosstalk Systems Inc.
*/
var assert = require( 'assert' );
var httpBodyEquals = function httpBodyEquals ( helper, obj ) {
var bodyEquals = function bodyEquals ( body ) {
if ( typeof( body ) == 'object' ) {
try {
var json = JSON.parse( obj.body.toString() );
assert.deepEqual( json, body );
} catch ( exception ) {
if ( exception.name == 'AssertionError' ) {
assert.fail( exception.actual, exception.expected, null,
exception.operator );
} // if AssertionError
assert.fail( JSON.stringify( body ), obj.body.toString(), null, "==" );
} // catch exception
} else if ( typeof( body ) == 'string' ) {
assert.equal( obj.body.toString(), body );
} else if ( typeof( body ) == 'function' ) {
body( obj.body );
}
return helper;
}; // bodyEquals
return bodyEquals;
}; // httpBodyEquals
module.exports = httpBodyEquals