robbrit robbrit - 6 months ago 25
CoffeeScript Question

Writing Mocha tests with IcedCoffeeScript?

I'm trying to run some database queries in a Mocha test but I'm running into some problems.

Here's the test (using Mongoose):

it.only "should create some objects", (done) ->
await models.MyModel1.count defer(err, oldModel1Count)
await models.MyModel2.count defer(err, oldModel2Count)

# ... do some stuff

await models.MyModel1.count defer(err, newModel1Count)
await models.MyModel2.count defer(err, newModel2Count)

assert.equal oldModel1Count + 1, newModel1Count
assert.equal oldModel2Count + 1, newModel2Count

The command for running the tests:

mocha --compilers coffee:iced-coffee-script --require iced-coffee-script --require mocha --colors --recursive test"

The error happens on the first line:

ReferenceError: err is not defined

I can only assume that it is attempting to use normal CoffeeScript to execute this code, so it thinks that
is a function and attempts to evaluate

Is it possible to write the Mocha tests in IcedCoffeeScript?


This works for me

mocha --require ./fix_my_iced_tests.js --compilers coffee:coffee-script

create fix_my_iced_tests.js


create test/ (this make sure that fix actually works)

assert = require 'assert'

describe 'test section', ()->
  it 'is ok', (done)->
    await setTimeout (defer next), 100
    assert.strictEqual(1, 1)

You should recieve something like this

  Type subdsl
    √ is ok (102ms)

  1 passing (109ms)

without fix you should recieve something like this

ReferenceError: next is not defined

--- EDITED ---

Much better option found here

mocha --compilers coffee:iced-coffee-script/register