Skip to content

Instantly share code, notes, and snippets.

@stim371
Created October 4, 2012 20:57
Show Gist options
  • Save stim371/3836403 to your computer and use it in GitHub Desktop.
Save stim371/3836403 to your computer and use it in GitHub Desktop.
example model test for question
describe 'Statement', ->
createStatement = (callback)->
domtest (window)->
Statement = window.require 'models/statement'
model = new Statement()
callback(model)
it 'can be initialized', (done)->
createStatement (model)->
should.exist(model)
# expect(model).to.exist
done()
## require or set up global helpers for tests - these will be automagically availabe in each test ##
chai = require('chai')
sinon = require('sinon')
global.expect = chai.expect
global.assert = chai.assert
global.should = chai.should()
global.sinon = sinon
# use jsdom to setup our test environment for dom-based tests
jsdom = require('jsdom');
global.domtest = (html, callback)->
if html instanceof Function
callback = html
html = '<html><body></body></html>'
jsdom.env(
html,
[
'../public/js/jquery.js'
'../public/js/vendor.js'
'../public/js/app.js'
],
(errors, window)->
console.log errors if errors
callback(window)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment