diff --git a/static/karma.src.js b/static/karma.src.js index 93b4bf33b..1c9a0c3b8 100644 --- a/static/karma.src.js +++ b/static/karma.src.js @@ -103,6 +103,10 @@ var Karma = function(socket, context, navigator, location) { contextWindow.dump = function() { self.log('dump', arguments); }; + + contextWindow.alert = function(msg) { + self.log('alert', [msg]); + }; }; this.log = function(type, args) { diff --git a/test/client/karma.spec.js b/test/client/karma.spec.js index e2229021f..6174125e6 100644 --- a/test/client/karma.spec.js +++ b/test/client/karma.spec.js @@ -84,6 +84,23 @@ describe('karma', function() { }); + describe('setupContext', function() { + it('should capture alert', function() { + spyOn(k, 'log'); + + var mockWindow = { + alert: function() { + throw 'Alert was not patched!'; + } + }; + + k.setupContext(mockWindow); + mockWindow.alert('What?'); + expect(k.log).toHaveBeenCalledWith('alert', ['What?']); + }) + }); + + describe('store', function() { it('should be getter/setter', function() {