From 3d50ae913143c252a63eb0d06eeddba6665d5083 Mon Sep 17 00:00:00 2001 From: Isaac Gierard Date: Fri, 16 Jan 2015 16:21:26 -0800 Subject: [PATCH] fixed uniqueid so that it is a function as expected by index.js and elsewhere also added test for uniqueid. only test that two calls to uniqueid return unique enties. had to modify the output slightly and added a counter to the system otherwise two back to back calls would return the same value. --- lib/uniqueid.js | 9 ++++++++- tests/lib/uniqueid.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/lib/uniqueid.js diff --git a/lib/uniqueid.js b/lib/uniqueid.js index 562770b..52a9bf0 100644 --- a/lib/uniqueid.js +++ b/lib/uniqueid.js @@ -1 +1,8 @@ -module.exports = "pjax" + (new Date().getTime()) +module.exports = (function() { + var counter = 0 + return function() { + var id = ("pjax" + (new Date().getTime())) + "_" + counter + counter++ + return id + } +})() diff --git a/tests/lib/uniqueid.js b/tests/lib/uniqueid.js new file mode 100644 index 0000000..5ad903c --- /dev/null +++ b/tests/lib/uniqueid.js @@ -0,0 +1,12 @@ +var tape = require("tape") + +var uniqueid = require("../../lib/uniqueid.js") + +tape("test uniqueid", function(t) { + var a = uniqueid() + var b = uniqueid() + + t.notEqual(a,b,"Two calls to uniqueid produce different values") + + t.end() +})