prop and withAttr tests
This commit is contained in:
parent
477e73f300
commit
a2c01d1d96
4 changed files with 61 additions and 1 deletions
17
util/tests/index.html
Normal file
17
util/tests/index.html
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<script src="../../module/module.js"></script>
|
||||
<script src="../../ospec/ospec.js"></script>
|
||||
|
||||
<script src="../../util/prop.js"></script>
|
||||
<script src="../../util/withAttr.js"></script>
|
||||
<script src="test-prop.js"></script>
|
||||
<script src="test-withAttr.js"></script>
|
||||
|
||||
<script>require("../../ospec/ospec").run()</script>
|
||||
</body>
|
||||
</html>
|
||||
16
util/tests/test-prop.js
Normal file
16
util/tests/test-prop.js
Normal file
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
25
util/tests/test-withAttr.js
Normal file
25
util/tests/test-withAttr.js
Normal file
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue