-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.spec.js
39 lines (36 loc) · 1.23 KB
/
index.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
const { expect } = require('chai');
const sinon = require('sinon');
const { main, counterModule} = require('./');
describe('module-pattern', () => {
describe('counterModule', () => {
beforeEach(() => {
counterModule.resetCounter();
});
it('should increase the value when calling increaseCounter', () => {
counterModule.increaseCounter();
expect(counterModule.counter).to.equal(1);
});
it('should decrease the value when calling decreaseCounter', () => {
counterModule.decreaseCounter();
expect(counterModule.counter).to.equal(-1);
});
});
describe('main', () => {
beforeEach(() => {
sinon.stub(counterModule, 'increaseCounter');
sinon.stub(counterModule, 'decreaseCounter');
});
afterEach(() => {
counterModule.increaseCounter.restore();
counterModule.decreaseCounter.restore();
});
it('should call increaseCounter', () => {
main();
expect(counterModule.increaseCounter).to.be.called;
});
it('should call decreaseCounter', () => {
main();
expect(counterModule.decreaseCounter).to.be.called;
});
});
});