Skip to content

Instantly share code, notes, and snippets.

@heymichaelp
Last active August 29, 2015 14:02
Show Gist options
  • Save heymichaelp/d3238c5f93ab1b173d6e to your computer and use it in GitHub Desktop.
Save heymichaelp/d3238c5f93ab1b173d6e to your computer and use it in GitHub Desktop.
Form Objects: Testing
var _ = require('underscore')
var expect = require('chai').expect
var sinon = require("sinon")
var sinonChai = require("sinon-chai")
chai.use(sinonChai)
var NewStudentForm = require('./NewStudentForm')
describe('NewStudentForm', function(){
describe('Valid Form Data', function(){
before(function(){
// spy on the this.persist method to see if it's called or not
this.persistSpy = sinon.spy(NewStudentForm.prototype, 'persist')
this.newStudentForm = new NewStudentForm({
firstName: 'John',
lastName: 'Smith',
gender: 'm'
}).process()
})
after(function() {
this.persistSpy.restore()
})
it('persists the data', function(){
expect(this.persistSpy).to.have.beenCalled
})
it('does not have errors', function(){
expect(this.newStudentForm.errors.length).to.eq(0)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment