summaryrefslogtreecommitdiffstats
path: root/tests/bind.js
blob: c76a0f40bfd2dfa798f8d066c2362abe64b84481 (plain)
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
import { bind } from '..';
import { expect } from 'chai';

/*global describe,it*/

describe('bind()', () => {
	it('should bind when used as a simple decorator', next => {
		let c = {
			@bind
			foo() {
				return this;
			}
		};

		expect(c.foo()).to.equal(c);

		let p = c.foo;
		expect(p()).to.equal(c);

		let a = {};
		expect(c.foo.call(a)).to.equal(c);

		next();
	});

	it('should bind when used as a function', next => {
		let ctx = {},
			c = bind(function(){ return this; }, ctx);

		expect(c()).to.equal(ctx);

		let a = {};
		expect(c.call(a)).to.equal(ctx);

		next();
	});
});