Writing Mocha Tests with IcedCoffeeScript?

I am trying to run some database queries in a Mocha test, but I am having 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 

Command to run tests:

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

The error in the first line:

 ReferenceError: err is not defined 

I can only assume that he is trying to use regular CoffeeScript to execute this code, so he thinks defer is a function and trying to evaluate err .

Can I write Mocha tests in IcedCoffeeScript?

+4
source share
2 answers

It works for me

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

create fix_my_iced_tests.js

 require('iced-coffee-script').register() 

create test / some_test.coffee (make sure the fix really works)

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

You should get something like this

  Type subdsl โˆš is ok (102ms) 1 passing (109ms) 

without correction you should get something like this

 ReferenceError: next is not defined 

--- EDITED ---

Much better to find here

 mocha --compilers coffee:iced-coffee-script/register 
+3
source

I'm not sure if this is still relevant, but now 2015, Node.js has first-class support for Promises and generators, which allows you to write code exactly as concise and elegant as IcedCoffeeScript, but with much less wrinkles.

0
source

Source: https://habr.com/ru/post/1488507/


All Articles