Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check before trying to extend objects
- Loading branch information
Showing
2 changed files
with
34 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var test = require("tap").test; | ||
var chain = require('../../'); | ||
|
||
test("non extensible Error objects don't throw", function(t) { | ||
var error = new Error("don't extend me"); | ||
Object.preventExtensions(error) | ||
t.doesNotThrow(function() { | ||
error.stack; | ||
}); | ||
t.end(); | ||
}); | ||
|
||
test('stack is correct on non extensible error object', function (t) { | ||
var error = new Error("don't extend me"); | ||
Object.preventExtensions(error); | ||
|
||
chain.format.replace(function () { | ||
return 'good'; | ||
}); | ||
|
||
try { | ||
t.equal(error.stack, 'good'); | ||
} catch (e) { t.ifError(e); } | ||
|
||
chain.format.restore(); | ||
|
||
t.end(); | ||
}); | ||
|