Skip to content

Instantly share code, notes, and snippets.

@PolCPP
Created July 20, 2012 20:07
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 PolCPP/3152917 to your computer and use it in GitHub Desktop.
Save PolCPP/3152917 to your computer and use it in GitHub Desktop.
Strange behavior with mocha/chai/sequelize
chai = require "chai"
crypto = require "crypto"
Sequelize = require "sequelize"
chai.should()
sequelize = new Sequelize 'talk', 'root','root', {
host: 'localhost'
logging: false
}
User = sequelize.define 'User', {
name: type: Sequelize.STRING,
key: type: Sequelize.STRING,
level: type: Sequelize.INTEGER, defaultValue: 0
}, instanceMethods: {
addKey: (key) ->
this.key = crypto.createHash('md5').update(key).digest("hex");
}
describe 'User instance', ->
it 'Should insert to db', (done) ->
user1 = User.build { name: 'John Doe' }
user1.save().success ->
# Let's make it fail from here
user1.id.should.equal null
done()
it 'Should insert to db', (done) ->
user1 = User.build { name: 'John Doe' }
user1.save().success ->
user1.id.should.not.equal null
done()
PolCPP$ mocha --compilers coffee:coffee-script -R spec
User instance
1) Should insert to db
2) Should insert to db
✖ 2 of 2 tests failed:
1) User instance Should insert to db:
expected 89 to equal null
2) User instance Should insert to db:
Error: timeout of 2000ms exceeded
at Object.<anonymous> (/usr/local/lib/node_modules/mocha/lib/runnable.js:142:14)
at Timer.ontimeout (timers.js:94:19)
chai = require "chai"
crypto = require "crypto"
Sequelize = require "sequelize"
chai.should()
sequelize = new Sequelize 'talk', 'root','root', {
host: 'localhost'
logging: false
}
User = sequelize.define 'User', {
name: type: Sequelize.STRING,
key: type: Sequelize.STRING,
level: type: Sequelize.INTEGER, defaultValue: 0
}, instanceMethods: {
addKey: (key) ->
this.key = crypto.createHash('md5').update(key).digest("hex");
}
describe 'User instance', ->
it 'Should insert to db', (done) ->
user1 = User.build { name: 'John Doe' }
user1.save().success ->
user1.id.should.not.equal null
done()
it 'Should insert to db', (done) ->
user1 = User.build { name: 'John Doe' }
user1.save().success ->
user1.id.should.not.equal null
done()
$ mocha --compilers coffee:coffee-script -R spec
User instance
✓ Should insert to db
✓ Should insert to db
✔ 2 tests complete (28ms)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment