jasmine-jquery プラグインを使用して Jquery テストを実行できません。これが私が取ったステップです:
- gem インストール ジャスミン
- ジャスミン初期
- jquery と jasmine-jquery をヘルパー フォルダーに追加します。
- ここに私のリポジトリがありますhttps://github.com/shenst1/jasminesample
これらのチュートリアルに従って推奨される私の仕様は次のとおりです: https://www.youtube.com/watch?v=3Huh44nsZTw
describe("My Feature", function() {
it("should add numbers", function() {
expect(1+1).toBe(2);
});
});
describe("experimentation", function() {
var elem;
beforeEach(function() {
elem = $('<div id="container"><p>Hello World</p></div>');
});
it("allows us to serach with Css selectors", function() {
expect(elem).toBe('#container');
expect(elem).toContainElement('p');
expect(elem).toEqual('#container');
expect(elem).toEqual('p')
});
});
最初の仕様は期待どおりに合格しますが、jquery を使用した 2 番目の仕様は次のエラーで失敗します。
Expected { 0 : HTMLNode, length : 1 } to be '#container'.
Error: Expected { 0 : HTMLNode, length : 1 } to be '#container'.
at stack (http://localhost:8888/__jasmine__/jasmine.js:1293:17)
at buildExpectationResult (http://localhost:8888/__jasmine__/jasmine.js:1270:14)
at Spec.Env.expectationResultFactory (http://localhost:8888/__jasmine__/jasmine.js:484:18)
at Spec.addExpectationResult (http://localhost:8888/__jasmine__/jasmine.js:260:46)
at Expectation.addExpectationResult (http://localhost:8888/__jasmine__/jasmine.js:442:21)
at Expectation.toBe (http://localhost:8888/__jasmine__/jasmine.js:1209:12)
at Object.<anonymous> (http://localhost:8888/__spec__/testSpec.js:12:18)
at attemptSync (http://localhost:8888/__jasmine__/jasmine.js:1510:12)
at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:1498:9)
at QueueRunner.execute (http://localhost:8888/__jasmine__/jasmine.js:1485:10)
TypeError: Object #<Expectation> has no method 'toContainElement'
TypeError: Object #<Expectation> has no method 'toContainElement'
at Object.<anonymous> (http://localhost:8888/__spec__/testSpec.js:13:18)
at attemptSync (http://localhost:8888/__jasmine__/jasmine.js:1510:12)
jquery マッチャーが正しく読み込まれていないようです。HTML要素をチェックするのではなく、オブジェクトを文字列に変換しているようです。Support Jasmine v2.0 (バージョン 1.5.92) の jasmine-jquery.js バージョンを使用しようとしましたが、同じエラーで失敗しました。Jquery をサポートするために jasmine のバージョンをロールバックする必要がありますか、それとも jquery で動作させる方法について何か不足していますか? ありがとう、アンドリュー