File: test.js

package info (click to toggle)
node-tap 12.0.1+ds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,916 kB
  • sloc: makefile: 84; sh: 75
file content (48 lines) | stat: -rw-r--r-- 918 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const t = require('../')
var bindObj = require('./bind-obj-methods.js')
var obj, m

function makeObj () {
  var obj = {
    method: function () { return this.foo },
    foo: 'bar'
  }

  Object.defineProperty(obj, 'secretMethod', {
    value: function () {
      return 'secret' + this.method()
    },
    enumerable: false,
    configurable: true,
    writable: true
  })

  return obj
}

// pretend we already bound secretMethod
obj = makeObj()
bindObj(obj, null, [ 'secretMethod', 'method' ])
m = obj.method
t.equal(m(), undefined)
m = obj.secretMethod
t.throws(m)

obj = makeObj()
bindObj(obj, obj, { secretMethod: true })
m = obj.method
t.equal(m(), 'bar')
m = obj.secretMethod
t.throws(m)

obj = makeObj()
bindObj(obj, obj)
m = obj.method
t.equal(m(), 'bar')
m = obj.secretMethod
t.equal(m(), 'secretbar')

obj = makeObj()
bindObj(obj, Object.prototype)
m = obj.hasOwnProperty
t.equal(m('hasOwnProperty'), true)