1 |
|
2 |
|
3 |
|
4 |
|
5 | 'use strict'
|
6 |
|
7 | const abind = require('../lib/abind.js')
|
8 | const assert = require('assert')
|
9 | const co = require('co')
|
10 |
|
11 | describe('abind', function () {
|
12 | this.timeout(3000)
|
13 |
|
14 | before(() => co(function * () {
|
15 |
|
16 | }))
|
17 |
|
18 | after(() => co(function * () {
|
19 |
|
20 | }))
|
21 |
|
22 | it('Abind', () => co(function * () {
|
23 | class Talker {
|
24 | constructor (name) {
|
25 | const s = this
|
26 | s.name = name
|
27 | abind(s)
|
28 | }
|
29 |
|
30 | sayHi () {
|
31 | const s = this
|
32 | return `Hi, i'm ${s.name}`
|
33 | }
|
34 |
|
35 | get yesName () {
|
36 | const s = this
|
37 | return `Yes,${s.name}`
|
38 | }
|
39 | }
|
40 |
|
41 | let talker = new Talker('Tom')
|
42 | let { sayHi, yesName } = talker
|
43 | assert.equal(sayHi(), "Hi, i'm Tom")
|
44 | assert.equal(yesName, 'Yes,Tom')
|
45 | talker.name = 'John'
|
46 | assert.equal(talker.yesName, 'Yes,John')
|
47 | }))
|
48 | })
|
49 |
|
50 |
|