I've came across a weird problem, and I cannot figure out why it's doing it.
I'm using express-coffeescript as the framework, mocha for testing along with should, chai, and zombiejs for the browser testing.
request = require 'request'
Browser = require 'zombie'
assert = require 'assert'
chai = require 'chai'
should = require 'should'
expect = chai.expect
chai.should
browser = new Browser()
describe 'GET /login', ->
it 'should login a user successfully', (done) ->
browser.on "error", ->
console.log "Error"
browser.visit "http://localhost/test-laravel/public/login", (browser), ->
browser.fill "username", "TheHydroImpulse"
browser.fill "password", "SomePassword123"
browser.pressButton "login", ->
console.log browser.location.pathname
should.equal "randomTextHere", "/test-laravel/public/dashboard"
This code works perfectly fine, the test fails of course when running
mocha test --compilers coffee:coffee-script -R spec
The weird thing about this or the problem is when I make the test pass.
should.equal "/test-laravel/public/dashboard", "/test-laravel/public/dashboard"
The test should pass, but instead it hangs for a couple seconds than fails because of the timeout of 2000ms. I tried searching around but there doesn't seem to be anything documenting this problem, or maybe it's my own fault. I did just start learning coffee-script a few hours ago.
After the line:
should.equal "/test-laravel/public/dashboard", "/test-laravel/public/dashboard"
call the method:
done()
Doing this signals to mocha that the test has finished. This must happen because of the asynchronous nature of most code written on the Node.js platform.