Testing postMessage with Jasmine async doesn't work
I'm trying to use Jasmine 2.0 to write unit tests for some logic in an AngularJS app, but the logic is inside an event listener. From the controller: window.addEventListener('message', function(e) { if (e.data === "sendMessage()") { $scope.submit(); } }, false); And from the test file: describe("post message", function() { beforeEach(function(done) { var controller = createController(controllerParams); spyOn($scope, 'submit'); window.postMessage('sendMessage()', '*'); done(); }); it('should submit on a sent message', function (done) { expect($scope.submit).toHaveBeenCalled(); done(); }); });