Created
July 20, 2016 18:30
-
-
Save dijs/e8f96c247e328ececebcf70c81c27ecf to your computer and use it in GitHub Desktop.
Example of testing iframe messaging using jsdom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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