Skip to content

Instantly share code, notes, and snippets.

@fgalassi
Created November 29, 2012 08:54
Show Gist options
  • Save fgalassi/4167685 to your computer and use it in GitHub Desktop.
Save fgalassi/4167685 to your computer and use it in GitHub Desktop.
test.coffee
describe "wait after pressButton", ->
before (done)->
brains.get "/two-timers-only-the-first-useful", (req,res)->
res.send """
<html>
<body>
<button id="pressMe">press me</button>
<script>
var button = document.getElementById("pressMe")
button.addEventListener("click", function(ev) {
ev.preventDefault()
setTimeout(function() {
window.useful = true
}, 1000)
setTimeout(function() {
console.log("useless!")
}, 3000)
}, false)
</script>
</body>
</html>
"""
brains.ready done
it "shoudnt wait 3 seconds", (done)->
@browser = new Browser()
@browser.visit("/two-timers-only-the-first-useful")
.then =>
@browser.startTime = new Date()
@browser.pressButton("#pressMe")
.then =>
@browser.wait function: -> @browser.window.useful is true
.then =>
timeElapsed = new Date() - @browser.startTime
assert(timeElapsed < 3000, "time elapsed is bigger than 3 seconds")
.then(done, done)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment