私は反応が非常に新しく、私はトランスファーなしでReact 14を使ってコードを書いています。今私は単体テストにKarma-Jasmineを使用したいと思いますが、私のテストではアプリケーションのレンダリングに失敗しているようです。 ユニットテストはカルマとジャスミンを使用して反応します
I以下の構造を有する:node_modules
MyApp/
/js/ *.js
/test/*.js
Karma.conf.js
package.json
index.html
私のindex.html:
<html>
<div id="content"></div>
<script src="js/react-0.14.7.js"></script>
<script src="js/react-dom-0.14.7.js"></script>
<script src="js/App.js"></script>
<script src="js/main.js"></script>
<link rel="stylesheet" href="style.css">
</body>
</html>
マイmain.js:
ReactDOM.render(React.createElement(App), document.getElementById('content'))
私のアプリは、その後、以下のようなものです:
var h = React.createElement;
var Command = React.createClass({
render: function(){
return h(....)
}
})
次のように私のテストコードは次のとおりです。
describe('App', function() {
beforeEach(function() {
fixture.load('index.htm');
});
beforeEach(function() {
ReactDOM.render(React.createElement(App), document.getElementById('content'));
});
it('accepts elements', function() {
document.getElementById('x').value = 1;
document.getElementById('y').value = 2;
document.getElementById('setbtn').click();
});
});
そして、ここではエラーです:
Uncaught ReferenceError: App is not defined
at main.js:2
(anonymous) @ main.js:2
debug.html:1 (WEB_PAGE context) Lazy require of app.binding did not set the binding field
.
.
.
ReferenceError: fixture is not defined
at UserContext.<anonymous> (main.test.js:6)
デバッグカルマは私のコンポーネントで機能を見ることができるように私のファイルがロードされている示しています。私はHtml2jsをインストールし、私のKarma.conf.jsに追加しました。私はウェブ上のほとんどの文書を読んだが、助けにはならなかった。
私は間違っていますか? I
「Uncaught ReferenceError:App is not defined」 - 「App」ではなく「Command」というグローバル変数としてエクスポートしているようです。また、karma-fixtureも含める必要があります(インストール手順はgithub.com/billtrik/karma-fixtureを参照してください)。最後に、あなたのHTMLが不正です。オープニングボディータグはありません –