Created
May 20, 2013 23:50
-
-
Save simon-lang/5616529 to your computer and use it in GitHub Desktop.
unit testing with jsdom and jquery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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