Skip to content

Instantly share code, notes, and snippets.

@ingoe
Created April 24, 2014 18:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ingoe/11265248 to your computer and use it in GitHub Desktop.
Save ingoe/11265248 to your computer and use it in GitHub Desktop.
window addEventHandler test
describe('window.postMessage test', function() {
var o;
beforeEach(function(done) {
o = {
f: function() {}
};
// won't pass the spec
// window.addEventListener('message', o.f, false);
spyOn(o, 'f').and.callFake(function() {
done();
});
// will pass the spec
window.addEventListener('message', o.f, false);
window.postMessage('another bam', '*');
});
it('works...', function() {
expect(o.f).toHaveBeenCalled();
});
});
@ingoe
Copy link
Author

ingoe commented Apr 28, 2014

describe('window.postMessage test', function() {
    var o;
    beforeEach(function(done) {
        o = {
            f: function() {
                o.f2();
            },
            f2: function() {}
        };
        window.addEventListener('message', o.f, false);
        spyOn(o, 'f2').and.callFake(function() {
            done();
        });
        window.postMessage('another bam', '*');
    });
    it('works...', function() {
        expect(o.f2).toHaveBeenCalled();
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment