RequireJS と mocha の連携には問題があります。これは、モカがrequireJSの非同期操作が完了するのを待たず、テストが完了したと判断したためだと考えました。
ホット フィックスとして、 requireJS の読み込み呼び出しを mocha のit()
呼び出しにラップしました。非同期メソッドが完了するまで待機する必要があることを、コールバックを追加するときにどういうわけかモカは知っています。
しかし、私が今使っているものよりも便利なセットアップが他にないかどうか知りたい. 現在のセットアップは、あまり良くも柔軟でもありません。
これは私の test.coffee スクリプトです:
describe 'Ink', ->
describe '#constructor', ->
it 'should return an Ink instance', ( done ) ->
requirejs [ "build/ink/core/Ink" ], ->
# commence testing
a = new Ink( '<div></div>' )
assert.equal( new Ink instanceof Ink, false )
assert.equal( new Ink instanceof window.jQuery, true )
done()
describe 'Mixin', ->
f : ( Mixin ) ->
# test mixin
class A
constructor : ( @a ) ->
class m extends Mixin
constructor : () -> @mixin_prop = 42
increment : ( arg ) -> return arg + 1
class B extends A
Mixin.mixin( m, @ )
b = new B()
return b
it 'should chain the constructor', ( done ) ->
requirejs [ "build/ink/core/Mixin" ], ( Mixin ) ->
b = f( Mixin )
assert.equal( b.mixin_prop, 42 )
done()
it 'should add the methods from the mixin to the new class', ( done ) ->
requirejs [ "build/ink/core/Mixin" ], ( Mixin ) ->
b = f( Mixin )
assert.equal( b.increment( 42 ), 42 )
done()