I was bumping my had against a wall whit unit testing class method that returns promise. So I tried to comment the logic and simply make the method to return new Promise that calls resolve. Still no luck ... So When I pass a function that simply calls done() to .then all is ok. But when I pass function that tests if 3 is 4 and then calls done() it timeouts.
This is my "promise" method:
class Session
constructor: (@ip) ->
@map = []
@get = {}
add: (doc, index = -1) ->
@get[doc.key] = JSON.parse doc.value
if index is -1
@map.push doc
else
@map[index] = doc
ready: ->
new Promise (resolve, reject) -> resolve()
#store.find ip: @ip, (err, docs) =>
# if successful err, docs then resolve()
# else reject err
....
And this are my 2 unit tests (first passes, second exeeds time limit) :
describe "ready", ->
session = undefined
beforeEach ->
Session = proxyquire "./../Session", "./sessionModel":mockSessionModel
session = new Session "ip"
it "simply calls done()", (done) ->
session.ready().then -> done()
it "make a fail assertaion", (done) ->
session.ready().then ->
expect(3).to.equal(4)
done()
Aucun commentaire:
Enregistrer un commentaire