Closed TrangPham closed 9 years ago
I'm a little unsure what you're asking. The test you're looking at in teaspoon is a capybara test, and is just testing teaspoon usage and has nothing to do with what you may be trying to do.
If I were to take a stab at what you're trying to do, you're calling a method in javascript that in turn calls alert
-- what you probably want to do is to to stub (spy, whatever) window.alert
-- then assert that the value of the alert is what you expect to see -- or don't that's up to you.
Teaspoon has nothing to do with capybara, which is what that thoughtbot article is about, and runs strictly in the browser.
Maybe a better example of spying on window.alert
can be found here? https://github.com/jejacks0n/mercury/blob/1cc637b0bccea19085f824d2881c6513ed5ee8ae/spec/javascripts/mercury/mercury_spec.js.coffee#L35
@jejacks0n Ah thank you! Your advice helped me find the correct answer, which was to use sinon to stub out the confirm dialog as follows:
sinon.stub(window, "confirm").returns(true);
This is a bit of a question.
Currently I am seeing this error, because I'm using a
confirm("Are you sure?")
dialog.I am using selenium web driver and am not sure how to access the
page
or thedriver
so that I could do:I got this from: https://robots.thoughtbot.com/interacting-with-a-javascript-confirmation-from
I see in one of the tests for teaspoon that there is one that
visits '/teaspoon'
and then does anexpect(page)
. But I am also using magic_lamp for fixtures. Could this be why thepage
variable is not accessible for me?