-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgetSerializableError.spec.js
More file actions
47 lines (45 loc) · 1.79 KB
/
getSerializableError.spec.js
File metadata and controls
47 lines (45 loc) · 1.79 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
"use strict";
var request = require("request");
describe("when serializing and deserializing a normal error", function () {
it('will not give the same result', function () {
var error = new Error("This is my error");
var serialized = JSON.parse(JSON.stringify(error));
expect(serialized.stack).not.to.be.ok;
});
});
describe("when passed an error", function () {
it('will make an error that is serializable', function () {
var getSerialiazableError = require("../../lib/util/getSerializableError");
var error = getSerialiazableError(new Error("This is my error"));
var serialized = JSON.parse(JSON.stringify(error));
expect(serialized.stack).to.be.ok;
expect(error).to.eql(serialized);
});
it('will make only copy properties that can be JSON.serialized', function () {
var getSerialiazableError = require("../../lib/util/getSerializableError");
var sourceError = new Error("This is my error");
//create circular reference
var o = { circle:{}};
o.circle = o;
sourceError.test = o;
var error = getSerialiazableError(sourceError);
var serialized = JSON.parse(JSON.stringify(error));
expect(serialized.stack).to.be.ok;
expect(error).to.eql(serialized);
});
it('will not crash on big objects JSON.serialized', function (done) {
var getSerialiazableError = require("../../lib/util/getSerializableError");
var sourceError = new Error("This is my error");
//get request response, that will reak havoc on the node process if JSON.stringify is run on it
request.get("http://google.com", function(err, response){
for(var i=0; i<1000; i++){
sourceError[i] = response;
}
var error = getSerialiazableError(sourceError);
var serialized = JSON.parse(JSON.stringify(error));
expect(serialized.stack).to.be.ok;
expect(error).to.eql(serialized);
return done();
});
});
});