-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.js
62 lines (48 loc) · 1.68 KB
/
tests.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
57
58
59
60
61
62
'use strict';
var sinon = require('sinon');
var globalRewire = require('../../');
describe('global-rewire', function() {
beforeEach(function() {
globalRewire.enable();
});
afterEach(function() {
globalRewire.disable();
});
it('should let you require a file', function() {
assert.doesNotThrow(function() {
require('../fixtures/module');
});
});
it('should let you get privateState', function() {
var mod = require('../fixtures/module');
assert.equal(mod.__get__('privateState'), 1);
});
it('should let you call privateFunction', function() {
var mod = require('../fixtures/module');
var func = mod.__get__('privateFunction');
assert.equal(func(), 1);
});
it('privateCall should return result from privateFunction', function() {
var mod = require('../fixtures/module');
assert.equal(mod.privateCall(), 1);
});
it('should let you change privateFunction', function() {
var mod = require('../fixtures/module');
mod.__set__('privateFunction', sinon.stub().returns(2));
assert.equal(mod.privateCall(), 2);
});
it('should not set on non functions', function() {
var bool = require('../fixtures/boolean');
assert.isUndefined(bool.__set__);
});
it('should not make __get__ and __set__ and __with__ enumerable', function() {
var keys = require('../fixtures/keys');
assert.notInclude(Object.keys(keys), '__get__');
assert.notInclude(Object.keys(keys), '__set__');
assert.notInclude(Object.keys(keys), '__with__');
});
it('should attach to files without semicolons', function() {
var semicolons = require('../fixtures/no-end-line-semicolons');
assert.isDefined(semicolons.__set__);
});
});