Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save simon-lang/5616529 to your computer and use it in GitHub Desktop.
Save simon-lang/5616529 to your computer and use it in GitHub Desktop.
unit testing with jsdom and jquery
should = require 'should'
mocha = require 'mocha'
jsdom = require 'jsdom'
global._ = require 'underscore'
global.window = jsdom.jsdom().createWindow() # Create a fake DOM/jQuery for testing UI components
global.document = window.document
global.$ = require('jquery').create(window) # WARNING: jQuery for testing is 1.8.3 - different to app
$.extend $.fn, fastClick: $.fn.click # extend jQuery with a faux fastClick method
game = null
gameView = null
describe 'Game View', ->
beforeEach ->
game = new Game {name: 'test game'}
gameView = new GameView game
it 'bound to Game', ->
gameView.model.should.eql game
describe 'Components', ->
it 'Name', ->
gameView.components.name.is(':visible').should.eql false
gameView.components.name.text().should.eql game.name
game.name = 'asdasdasd'
gameView.components.name.text().should.eql game.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment