37

RailsアプリケーションでCoffeeScriptを使用していますが、単体テストを行いたいと思います。Googleは何も発表しませんでしたが、独自のテストフレームワークを作成したり、CoffeeScriptが出力するJavaScriptをテストしたりする以外に、それを行う方法はありますか?

4

4 に答える 4

26

You can use any javascript testing framework with CoffeeScript. This will be testing the Javascript that CoffeeScript outputs which is necessary since CoffeeScript itself can't be executed.

Writing your own testing framework for CoffeeScript is fun (I did) but entirely uneccessary.

UPDATE: Jasmine tests can be run on node.js in which case both the tests and the code under test can be CoffeeScript, without the need for any compilation step.

于 2010-06-28T05:12:47.697 に答える
11

QUnitは「現状のまま」使用できますが、それでもコーヒースクリプトのみを記述し、グルーコードは記述しません。
例として、githubに非常に小さく純粋なコーヒースクリプトプロジェクトがあります-rubyann

HTMLテストページrubyann_tests.htmlは、 jquery.rubyann.coffeeをテストするrubyann_tests.coffeeファイルを参照します。これを機能させるために、JavaScriptやその他のコードを記述していません。

コマンドライン引数--allow-file-access-from-filesを使用する場合、テストはローカルマシンのChromeでのみ実行されます。しかし、FirefoxやIEでも問題なく動作します。

補遺-テストは、Node / gulp/qunitjsを介してコマンドラインで実行するようにも設定されています-リポジトリをダウンロードして次のように入力しますnpm run test

于 2011-01-10T11:13:56.180 に答える
3

RailsアプリでQUnitを使用してCoffeeScriptをテストしており、その方法をここに記述しています:http: //effectif.com/coffeescript/qunit-boilerplate

私の記事で最も興味深いのは、Coffee.loadへのコールバックを使用して、テストを含むファイルがテスト対象のコードを含むファイルの後にロードされることを保証することです。

<script type="text/coffeescript">
  for file in ['models', 'controllers']                                             
    lib = "../../app/assets/javascripts/#{file}.js.coffee"                          
    load_test = ->                                                                  
      test = "#{file}_test.coffee"                                                  
      -> CoffeeScript.load(test)                                                    
    CoffeeScript.load lib, load_test()  
</script>

test変数をカリー化する必要性は、記事で説明されています...

于 2012-04-04T08:20:30.447 に答える
0

For Coffee-Script Unit testing you can try Beast-Test it was written from the ground up for coffee-script. FYI i am the own but i think you will like it none the less. It is similar to JUnit

于 2014-04-18T17:42:29.443 に答える