Skip to content

Instantly share code, notes, and snippets.

@ccidral
Last active December 14, 2015 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ccidral/5026187 to your computer and use it in GitHub Desktop.
Save ccidral/5026187 to your computer and use it in GitHub Desktop.
Basic test with mocha + phantomjs
phantom = require 'phantom'
assert = require 'assert'
{WebServer} = require '../webserver'
class EmptySystem
listSomething: -> [1, 2, 3]
class Browser
go: (uri, callback) ->
phantom.create (browser) =>
browser.createPage (page) =>
@page = page
url = 'http://localhost:9001' + uri
page.open url, (status) =>
error = if status != 'success' then 'http error' else undefined
callback error
describe 'Smoke test', ->
system = new EmptySystem
webServer = new WebServer(9001, system)
before (done) ->
webServer.start done
describe 'The home page', ->
browser = new Browser
before (done) ->
browser.go '/', done
it 'Should have the right title', (done) ->
browser.page.evaluate (-> document.title), (title) ->
assert.equal title, 'Foo Bar'
done()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment