Skip to content

Instantly share code, notes, and snippets.

@hustcc
Forked from dijs/jsdom-iframe-test.js
Created January 15, 2018 10:43
Show Gist options
  • Save hustcc/b65ad04b77f4a3fa6bca75af0d2ab81e to your computer and use it in GitHub Desktop.
Save hustcc/b65ad04b77f4a3fa6bca75af0d2ab81e to your computer and use it in GitHub Desktop.
Example of testing iframe messaging using jsdom
import { expect } from 'chai';
import jsdom from 'jsdom';
describe('JSDOM', () => {
it('should communicate with inner iframes', done => {
jsdom.env({
url: "http://bar.com/",
done (err, window) {
var frame = window.document.createElement('iframe');
window.document.body.appendChild(frame);
frame.contentWindow.addEventListener('message', e => {
expect(e.data.message).to.equal('hello');
done();
});
frame.contentWindow.postMessage({
message: 'hello'
}, '*');
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment