Skip to content

Commit fc10c10

Browse files
authored
Merge pull request #13 from oslabs-beta/rydang/jest-index
jest tests
2 parents 76ef00f + f714596 commit fc10c10

File tree

5 files changed

+2228
-14
lines changed

5 files changed

+2228
-14
lines changed

__tests__/index.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const index = require('../package/index');
2+
3+
jest.mock('../package/timeJump');
4+
5+
describe('unit testing for index.js', () => {
6+
test('index.js should be exporting the linkState and timeJump methods', () => {
7+
expect(typeof index.linkState).toBe('function');
8+
expect(typeof index.timeJump).toBe('function');
9+
});
10+
11+
test('index.js should be listening to the window for the jumpToSnap message', (done) => {
12+
const calls = 10;
13+
let count = 0;
14+
global.addEventListener('message', ({ data: { action } }) => {
15+
if (action === 'jumpToSnap') {
16+
count += 1;
17+
// timeJump should be called everytime a message is received
18+
expect(index.timeJump.mock.calls.length).toBe(count);
19+
20+
// test is done once all messages have been received
21+
if (count === calls) done();
22+
}
23+
});
24+
25+
// iterate ${calls} amount of times
26+
[...Array(calls).keys()].forEach(() => global.postMessage({ action: 'jumpToSnap', payload: ['test'] }, '*'));
27+
});
28+
});

0 commit comments

Comments
 (0)