我如何testing一个基本的JavaScript文件与摩卡?

我在这里用摩卡咖啡和Coffeescript / Javascript丢失了一些明显的东西。

我在/static/js/有一个名为ss.coffee ,它非常简单,只有一个函数:

 function sortRowCol(a, b) { if (ar == br) if (ac == bc) return 0; else if (ac > bc) return 1; else return -1; else if (ar > br) return 1; else return -1; } 

该function正常工作,但我决定我需要今天开始testing这个项目,所以我把一个摩卡testing文件:

 require "../static/js/ss.coffee" chai = require 'chai' chai.should() describe 'SS', -> describe '#sortRowCol(a,b)', -> it 'should have a sorting function', -> f = sortRowCol debugger console.log 'checking sort row' f.should.not.equal(null, "didn't find the sortRowCol function") describe 'sortRowCol(a, b)', -> it 'should return -1 when first row is less than second', -> a = {r: 2, c: "A"} b = {r: 1, c: "A"} r = sortRowCol a, b r.should.equal(-1, "didn't get the correct value") 

有些事情是不对的,因为我的结果是:

  $ mocha --compilers coffee:coffee-script ./test/ss.coffee -R spec SS #sortRowCol(a,b) 1) should have a sorting function sortRowCol(a, b) 2) should return -1 when first row is less than second × 2 of 2 tests failed: 1) SS #sortRowCol(a,b) should have a sorting function: ReferenceError: sortRowCol is not defined 

它正确地find该文件,因为如果将其更改为不存在的文件名,将会出现“无法find模块”的错误。

我试着改变sortRowCol(a,b)#sortRowCol(a, b) ,反之亦然,没有帮助。 文档( 链接 )并没有真正解释#在那里做什么,这只是一个ruby成语,在这里出于某种原因?

如何引用ss.coffee文件一定有什么问题,但我没有看到它。

通过在Node中require脚本,它将被视为任何其他模块 ,将sortRowCol作为闭包中的本地进行隔离。 该脚本将不得不使用exportsmodule.exports使其可用于mocha

 function sortRowCol(a, b) { // ... } if (typeof module !== 'undefined' && module.exports != null) { exports.sortRowCol = sortRowCol; } 
 ss = require "../static/js/ss.coffee" sortRowCol = ss.sortRowCol # ... 

至于…

文档(链接)并没有真正解释#在那里做什么,[…]

AFAIK, #通常用于暗示它是一个方法 – 例如, Constructor#methodName 。 但是,不确定这是否适用于此。