From a2c01d1d9674c28c968f0d3e9f43e195d8e8e31b Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Sat, 21 May 2016 09:49:05 -0400 Subject: [PATCH] prop and withAttr tests --- util/tests/index.html | 17 +++++++++++++++++ util/tests/test-prop.js | 16 ++++++++++++++++ util/tests/test-withAttr.js | 25 +++++++++++++++++++++++++ util/withAttr.js | 4 +++- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 util/tests/index.html create mode 100644 util/tests/test-prop.js create mode 100644 util/tests/test-withAttr.js diff --git a/util/tests/index.html b/util/tests/index.html new file mode 100644 index 00000000..e156fad4 --- /dev/null +++ b/util/tests/index.html @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/util/tests/test-prop.js b/util/tests/test-prop.js new file mode 100644 index 00000000..124c5d5a --- /dev/null +++ b/util/tests/test-prop.js @@ -0,0 +1,16 @@ +"use strict" + +var o = require("../../ospec/ospec") +var prop = require("../../util/prop") + +o.spec("prop", function() { + o("works", function() { + var store = prop(1) + var initialValue = store() + store(2) + var newValue = store() + + o(initialValue).equals(1) + o(newValue).equals(2) + }) +}) \ No newline at end of file diff --git a/util/tests/test-withAttr.js b/util/tests/test-withAttr.js new file mode 100644 index 00000000..d6fd6f4f --- /dev/null +++ b/util/tests/test-withAttr.js @@ -0,0 +1,25 @@ +"use strict" + +var o = require("../../ospec/ospec") +var withAttr = require("../../util/withAttr") + +o.spec("withAttr", function() { + o("works", function() { + var spy = o.spy() + var context = { + handler: withAttr("value", spy) + } + context.handler({currentTarget: {value: 1}}) + + o(spy.args).deepEquals([1]) + o(spy.this).equals(context) + }) + o("context arg works", function() { + var spy = o.spy() + var context = {} + var handler = withAttr("value", spy, context) + handler({currentTarget: {value: 1}}) + + o(spy.this).equals(context) + }) +}) \ No newline at end of file diff --git a/util/withAttr.js b/util/withAttr.js index 7b50b1f7..a949d062 100644 --- a/util/withAttr.js +++ b/util/withAttr.js @@ -1,5 +1,7 @@ "use strict" module.exports = function(attrName, callback, context) { - return callback.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName)) + return function(e) { + return callback.call(context || this, attrName in e.currentTarget ? e.currentTarget[attrName] : e.currentTarget.getAttribute(attrName)) + } } \ No newline at end of file