2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Karmaの ReferenceError: Can't find variable: chai エラーを解決

Posted at

フロントエンドエンジニア養成読本のテストランナーの項を写経してたら思いがけないエラーに遭遇したのでその解決方法。

まずは、本の通り、foo.jsとfoo_spec.jsを書いて設定ファイル(karma.conf.js)を作ってからターミナル上でKarmaを起動します。

すると、

PhantomJS 1.9.7 (Mac OS X) ERROR
ReferenceError: Can't find variable: chai

Chrome 36.0.1985 (Mac OS X 10.9.4) ERROR
Uncaught ReferenceError: chai is not defined

のエラーが。

そこで、

karma.conf.jsの中を見て、

frameworks: ['mocha'],の部分を
frameworks: ['mocha', 'chai'],と書き換えて再度ターミナル上でKarmaを起動します。

まだエラーが出ます。

module.js:340
throw err;
^
Error: Cannot find module 'chai'

念の為にchaiを単独でインストールしてみます。

npm install chai

無事、テストが通ります。

INFO [karma]: Karma v0.12.19 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Mac OS X)]: Connected on socket 1yosHgWYO8vtW1NoG0JF with id 34000027
INFO [Chrome 36.0.1985 (Mac OS X 10.9.4)]: Connected on socket nTYAK3C5ieGDveSCG0JG with id 84770794
PhantomJS 1.9.7 (Mac OS X): Executed 4 of 4 SUCCESS (0.004 secs / 0.003 secs)
PhantomJS 1.9.7 (Mac OS X): Executed 4 of 4 SUCCESS (0.004 secs / 0.003 secs)
PhantomJS 1.9.7 (Mac OS X): Executed 4 of 4 SUCCESS (0.004 secs / 0.003 secs)
PhantomJS 1.9.7 (Mac OS X): Executed 4 of 4 SUCCESS (0.004 secs / 0.003 secs)
PhantomJS 1.9.7 (Mac OS X): Executed 4 of 4 SUCCESS (0.004 secs / 0.003 secs)
Chrome 36.0.1985 (Mac OS X 10.9.4): Executed 4 of 4 SUCCESS (0.024 secs / 0.003 secs)
TOTAL: 8 SUCCESS

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?