Skip to content

Commit

Permalink
feat(client): capture confirm & prompt
Browse files Browse the repository at this point in the history
Capture `window.confirm` & `window.prompt` usages in client

Fixes #694
  • Loading branch information
wesleycho authored and dignifiedquire committed Jan 14, 2017
1 parent 35965d9 commit 3a618b3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions context/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,23 @@ var ContextKarma = function (callParentKarmaMethod) {
self.log('dump', arguments)
}

var _confirm = contextWindow.confirm
var _prompt = contextWindow.prompt

contextWindow.alert = function (msg) {
self.log('alert', [msg])
}

contextWindow.confirm = function (msg) {
self.log('confirm', [msg])
_confirm(msg)
}

contextWindow.prompt = function (msg, defaultVal) {
self.log('prompt', [msg, defaultVal])
_prompt(msg, defaultVal)
}

// If we want to overload our console, then do it
var getConsole = function (currentWindow) {
return currentWindow.console || {
Expand Down
32 changes: 32 additions & 0 deletions test/client/karma.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,38 @@ describe('Karma', function () {
mockWindow.alert('What?')
assert(ck.log.calledWith('alert', ['What?']))
})

it('should capture confirm', function () {
sinon.spy(ck, 'log')
var confirmCalled = false

var mockWindow = {
confirm: function () {
confirmCalled = true
}
}

ck.setupContext(mockWindow)
mockWindow.confirm('What?')
assert(ck.log.calledWith('confirm', ['What?']))
assert.equal(confirmCalled, true)
})

it('should capture prompt', function () {
sinon.spy(ck, 'log')
var promptCalled = false

var mockWindow = {
prompt: function () {
promptCalled = true
}
}

ck.setupContext(mockWindow)
mockWindow.prompt('What is your favorite color?', 'blue')
assert(ck.log.calledWith('prompt', ['What is your favorite color?', 'blue']))
assert.equal(promptCalled, true)
})
})

describe('complete', function () {
Expand Down

0 comments on commit 3a618b3

Please sign in to comment.