LoginSignup
5
5

More than 5 years have passed since last update.

Karma+Jasmine-jQueryでHTML fixtureをロードする

Last updated at Posted at 2015-08-20

Karmaでjasmine-jqueryを使ってHTML fixtureをよみこもうとして少しハマったという話。ちなみにテストフレームワークはJasmine。

1. fixtureの置かれたパスを設定する

Karmaから読み込む場合はbaseというディレトリがKarmaからみたルートディレクトリになる。そのため、$APP_ROOT/test/fixturesにフィクスチャーとなるhtmlを置いた場合は下記のようにテスト内で指定する

jasmine.getFixtures().fixturesPath = 'base/test/fixtures';

が、これだけだと読み込みできない

Error: Fixture could not be loaded: /Users/foo/Work/my_app/test/fixtures/baz.html (status: error, message: undefined)

2. Karmaでサーブするようkarm.conf.jsに書く

下記のようにincludedはfalseにした上でサーブする対象として指定する

karma.conf.js
    files: [
        'public/assets/js/*.js',
        'test/js/*js',
        {
            pattern: 'test/fixtures/*.html',
            watched: true,
            included: false,
            served: true
        }
    ],

とのように2点気をつけるとloadFixtureが動作するようになる

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5