diff --git a/src/lolex-src.js b/src/lolex-src.js index c1a51961..b19de4ca 100644 --- a/src/lolex-src.js +++ b/src/lolex-src.js @@ -356,10 +356,10 @@ for (i = 0, l = clock.methods.length; i < l; i++) { method = clock.methods[i]; - if (method === "hrtime") { + if (method === "hrtime" && target.process) { target.process.hrtime = clock[installedHrTime]; } else { - if (target[method].hadOwnProperty) { + if (target[method] && target[method].hadOwnProperty) { target[method] = clock["_" + method]; } else { try { diff --git a/test/lolex-test.js b/test/lolex-test.js index 3fda1d75..e773bb30 100644 --- a/test/lolex-test.js +++ b/test/lolex-test.js @@ -29,6 +29,21 @@ var GlobalDate = Date; var NOOP = function NOOP() { return undefined; }; var hrtimePresent = (global.process && typeof global.process.hrtime === "function"); +describe("issue #59", function () { + var context = { + Date: Date, + setTimeout: setTimeout, + clearTimeout: clearTimeout + }; + var clock; + + it("should install and uninstall the clock on a custom target", function () { + clock = lolex.install(context); + // this would throw an error before issue #59 was fixed + clock.uninstall(); + }); +}); + describe("lolex", function () { describe("setTimeout", function () {