/
index.js
56 lines (37 loc) · 1.03 KB
/
index.js
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
49
50
51
52
53
54
55
56
'use strict';
var expect = require('chai').expect;
describe('invoke-before: ', function () {
var invokeBefore = require('../../');
it('invokeBefore(1, func) => never be executed.', function () {
var c = 0;
var fn = invokeBefore(1, function () {
return ++c;
});
expect(fn()).to.be.equal(1);
expect(fn()).to.be.equal(2);
expect(fn()).to.be.equal(3);
});
it('invokeBefore(2, func) => only be executed once.', function () {
var c = 0;
var fn = invokeBefore(2, function () {
return ++c;
});
expect(fn()).to.be.undefined;
expect(fn()).to.be.equal(1);
expect(fn()).to.be.equal(2);
});
it('invokeBefore(3, func) => only be executed twice.', function () {
var c = 0;
var fn = invokeBefore(3, function () {
return ++c;
});
expect(fn()).to.be.undefined;
expect(fn()).to.be.undefined;
expect(fn()).to.be.equal(1);
});
it('exceptions', function () {
expect(function () {
invokeBefore(3, null);
}).to.throw(Error);
});
});