-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
48 lines (36 loc) · 1.35 KB
/
test.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
'use strict';
const assert = require('chai').assert;
const expect = require('jest').expect;
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
describe('IFrameActionCommunicator', () => {
before(() => {
const dom = new JSDOM(`<!DOCTYPE html><iframe id="iframe"></iframe>`);
global.window = dom.window;
global.IframeActionCommunicator = require('./dist/iframe-action-communicator');
});
describe('initialization', () => {
it('parent initialization', () => {
const iac = new IframeActionCommunicator('iframe');
assert.strictEqual(iac.parentInstance, true);
});
it('iframe initialization', () => {
const iac = new IframeActionCommunicator();
assert.strictEqual(iac.parentInstance, false);
});
});
describe('describing to actions', () => {
it('bind action with handler on parent', () => {
function actionHandler() {};
const iac = new IframeActionCommunicator('iframe');
iac.on('messageFromIframe', actionHandler);
assert.deepEqual(iac.registeredActions.messageFromIframe, actionHandler);
});
it('bind action with handler on iframe', () => {
function actionHandler() {};
const iac = new IframeActionCommunicator();
iac.on('messageFromParent', actionHandler);
assert.deepEqual(iac.registeredActions.messageFromParent, actionHandler);
});
});
});