-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
mocha.spec.js
82 lines (70 loc) · 2.49 KB
/
mocha.spec.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
const Mocha = require('../../lib/mocha');
const utils = require('../../lib/utils');
const {createSandbox} = require('sinon');
describe('Mocha', function() {
const opts = {reporter: utils.noop}; // no output
const dumbFilepath = require.resolve('./fixtures/dumb-module.fixture.js');
const dumberFilepath = require.resolve('./fixtures/dumber-module.fixture.js');
let mocha;
let sandbox;
beforeEach(function() {
sandbox = createSandbox();
mocha = new Mocha(opts);
delete require.cache[dumbFilepath];
delete require.cache[dumberFilepath];
});
afterEach(function() {
delete require.cache[dumbFilepath];
delete require.cache[dumberFilepath];
sandbox.restore();
});
describe('instance method', function() {
describe('addFile()', function() {
it('should add the given file to the files array', function() {
mocha.addFile('some-file.js');
expect(mocha.files, 'to exhaustively satisfy', ['some-file.js']);
});
it('should be chainable', function() {
expect(mocha.addFile('some-file.js'), 'to be', mocha);
});
});
describe('loadFiles()', function() {
it('should load all files from the files array', function() {
this.timeout(1000);
mocha.files = [dumbFilepath, dumberFilepath];
mocha.loadFiles();
expect(require.cache, 'to have keys', [dumbFilepath, dumberFilepath]);
});
it('should execute the optional callback if given', function() {
expect(cb => {
mocha.loadFiles(cb);
}, 'to call the callback');
});
});
describe('unloadFiles()', function() {
it('should delegate Mocha.unloadFile() for each item in its list of files', function() {
mocha.files = [dumbFilepath, dumberFilepath];
sandbox.stub(Mocha, 'unloadFile');
mocha.unloadFiles();
expect(Mocha.unloadFile, 'to have a call exhaustively satisfying', [
dumbFilepath
])
.and('to have a call exhaustively satisfying', [dumberFilepath])
.and('was called twice');
});
it('should be chainable', function() {
expect(mocha.unloadFiles(), 'to be', mocha);
});
});
});
describe('static method', function() {
describe('unloadFile()', function() {
it('should unload a specific file from cache', function() {
require(dumbFilepath);
Mocha.unloadFile(dumbFilepath);
expect(require.cache, 'not to have key', dumbFilepath);
});
});
});
});