-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.spec.js
33 lines (29 loc) · 1.22 KB
/
utils.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
const Utils = require('./utils.js');
describe ('Utils', () => {
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
});
it ("should call showMiniWarning() and set text HTML element.", () => {
const testMessage = "This is a test"
const mockElem = document.createElement('span');
mockElem.id = 'warning-message';
document.getElementById = jest.fn().mockReturnValue(mockElem);
Utils.showMiniWarning(testMessage);
expect(mockElem.textContent).toBe(testMessage);
})
it ("should call showMiniWarning(), first show a message with timeout and then a normal one.", () => {
const testMessage1 = "This is a test WITHOUT a timeout";
const testMessage2 = "This is a test WITH a timeout";
const mockElem = document.createElement('span');
mockElem.id = 'warning-message';
document.getElementById = jest.fn().mockReturnValue(mockElem);
Utils.showMiniWarning(testMessage1, 1000);
expect(mockElem.textContent).toBe(testMessage1);
jest.advanceTimersByTime(1000);
Utils.showMiniWarning(testMessage2);
expect(mockElem.textContent).toBe(testMessage2);
})
})