-
-
Save hustcc/b65ad04b77f4a3fa6bca75af0d2ab81e 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