Reputation: 46589
describe 'TheObject', ->
before ->
console.log 'loading text'
fs.readFile('../data/data.json', 'utf8', (err, data) ->
text = data
)
describe 'simple', ->
it 'should pass a simple test', ->
b = "1"
b.should.equal "1"
I'd like to make it so that none of my tests run until the file read in the before
action is complete. But this is asynch world here, so I think it's behaving as expected. Can I put all my other tests into a callback somehow? Can I force the readFile to be blocking?
Upvotes: 0
Views: 72
Reputation: 311945
When async, your before
function should accept a done
callback parameter that it calls when it's completed its processing:
describe 'TheObject', ->
before (done) ->
console.log 'loading text'
fs.readFile('../data/data.json', 'utf8', (err, data) ->
text = data
done()
)
Upvotes: 1