Sha256: cff4848cc860d6dad474f59a93540602dc24073a87f72bc856bed855177644b2

Contents?: true

Size: 1.1 KB

Versions: 735

Compression:

Stored size: 1.1 KB

Contents

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()
})

Version data entries

735 entries across 137 versions & 12 rubygems

Version Path
opal-0.11.4 stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js
opal-0.11.4 stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js
opal-0.11.3 stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js
opal-0.11.3 stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js
opal-0.11.2 stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js
opal-0.11.2 stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js
opal-0.11.1 stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js
opal-0.11.1 stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js
opal-0.11.1.pre stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js
opal-0.11.1.pre stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js
opal-0.10.6 stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js
opal-0.10.6 stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js
opal-0.10.6.beta stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js
opal-0.10.6.beta stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js
opal-0.11.0 stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js
opal-0.11.0 stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js
opal-0.10.5 stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js
opal-0.10.5 stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js
opal-0.10.4 stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js
opal-0.10.4 stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js