Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/wrappy/test/basic.js')
-rw-r--r--node_modules/wrappy/test/basic.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/node_modules/wrappy/test/basic.js b/node_modules/wrappy/test/basic.js
new file mode 100644
index 000000000..5ed0fcdfd
--- /dev/null
+++ b/node_modules/wrappy/test/basic.js
@@ -0,0 +1,51 @@
+var test = require('tap').test
+var wrappy = require('../wrappy.js')
+
+test('basic', function (t) {
+ function onceifier (cb) {
+ var called = false
+ return function () {
+ if (called) return
+ called = true
+ return cb.apply(this, arguments)
+ }
+ }
+ onceifier.iAmOnce = {}
+ var once = wrappy(onceifier)
+ t.equal(once.iAmOnce, onceifier.iAmOnce)
+
+ var called = 0
+ function boo () {
+ t.equal(called, 0)
+ called++
+ }
+ // has some rando property
+ boo.iAmBoo = true
+
+ var onlyPrintOnce = once(boo)
+
+ onlyPrintOnce() // prints 'boo'
+ onlyPrintOnce() // does nothing
+ t.equal(called, 1)
+
+ // random property is retained!
+ t.equal(onlyPrintOnce.iAmBoo, true)
+
+ var logs = []
+ var logwrap = wrappy(function (msg, cb) {
+ logs.push(msg + ' wrapping cb')
+ return function () {
+ logs.push(msg + ' before cb')
+ var ret = cb.apply(this, arguments)
+ logs.push(msg + ' after cb')
+ }
+ })
+
+ var c = logwrap('foo', function () {
+ t.same(logs, [ 'foo wrapping cb', 'foo before cb' ])
+ })
+ c()
+ t.same(logs, [ 'foo wrapping cb', 'foo before cb', 'foo after cb' ])
+
+ t.end()
+})