Skip to content

Commit 3a618b3

Browse files
wesleychodignifiedquire
authored andcommitted
feat(client): capture confirm & prompt
Capture `window.confirm` & `window.prompt` usages in client Fixes #694
1 parent 35965d9 commit 3a618b3

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

context/karma.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,23 @@ var ContextKarma = function (callParentKarmaMethod) {
8080
self.log('dump', arguments)
8181
}
8282

83+
var _confirm = contextWindow.confirm
84+
var _prompt = contextWindow.prompt
85+
8386
contextWindow.alert = function (msg) {
8487
self.log('alert', [msg])
8588
}
8689

90+
contextWindow.confirm = function (msg) {
91+
self.log('confirm', [msg])
92+
_confirm(msg)
93+
}
94+
95+
contextWindow.prompt = function (msg, defaultVal) {
96+
self.log('prompt', [msg, defaultVal])
97+
_prompt(msg, defaultVal)
98+
}
99+
87100
// If we want to overload our console, then do it
88101
var getConsole = function (currentWindow) {
89102
return currentWindow.console || {

test/client/karma.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,38 @@ describe('Karma', function () {
252252
mockWindow.alert('What?')
253253
assert(ck.log.calledWith('alert', ['What?']))
254254
})
255+
256+
it('should capture confirm', function () {
257+
sinon.spy(ck, 'log')
258+
var confirmCalled = false
259+
260+
var mockWindow = {
261+
confirm: function () {
262+
confirmCalled = true
263+
}
264+
}
265+
266+
ck.setupContext(mockWindow)
267+
mockWindow.confirm('What?')
268+
assert(ck.log.calledWith('confirm', ['What?']))
269+
assert.equal(confirmCalled, true)
270+
})
271+
272+
it('should capture prompt', function () {
273+
sinon.spy(ck, 'log')
274+
var promptCalled = false
275+
276+
var mockWindow = {
277+
prompt: function () {
278+
promptCalled = true
279+
}
280+
}
281+
282+
ck.setupContext(mockWindow)
283+
mockWindow.prompt('What is your favorite color?', 'blue')
284+
assert(ck.log.calledWith('prompt', ['What is your favorite color?', 'blue']))
285+
assert.equal(promptCalled, true)
286+
})
255287
})
256288

257289
describe('complete', function () {

0 commit comments

Comments
 (0)