Skip to content

Instantly share code, notes, and snippets.

@dijs
Created July 20, 2016 18:30
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dijs/e8f96c247e328ececebcf70c81c27ecf to your computer and use it in GitHub Desktop.
Save dijs/e8f96c247e328ececebcf70c81c27ecf 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