diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.js index fc703ce6f0..a249b232e3 100644 --- a/frontend_tests/node_tests/drafts.js +++ b/frontend_tests/node_tests/drafts.js @@ -21,13 +21,13 @@ set_global('localStorage', { }, }); -function stub_timestamp(model, timestamp, func) { - var original_func = model.getTimestamp; - model.getTimestamp = function () { +function stub_timestamp(timestamp, func) { + var original_func = Date.prototype.getTime; + Date.prototype.getTime = function () { return timestamp; }; func(); - model.getTimestamp = original_func; + Date.prototype.getTime = original_func; } var draft_1 = { @@ -64,10 +64,10 @@ var draft_2 = { localStorage.clear(); (function test_addDraft() { - stub_timestamp(draft_model, 1, function () { - var expected = draft_1; + stub_timestamp(1, function () { + var expected = _.clone(draft_1); expected.updatedAt = 1; - var id = draft_model.addDraft(draft_1); + var id = draft_model.addDraft(_.clone(draft_1)); assert.deepEqual(ls.get("drafts")[id], expected); }); @@ -75,11 +75,11 @@ var draft_2 = { localStorage.clear(); (function test_editDraft() { - stub_timestamp(draft_model, 2, function () { + stub_timestamp(2, function () { ls.set("drafts", { id1: draft_1 } ); - var expected = draft_2; + var expected = _.clone(draft_2); expected.updatedAt = 2; - draft_model.editDraft("id1", draft_2); + draft_model.editDraft("id1", _.clone(draft_2)); assert.deepEqual(ls.get("drafts").id1, expected); });