2

jasmine-jquery プラグインを使用して Jquery テストを実行できません。これが私が取ったステップです:

  1. gem インストール ジャスミン
  2. ジャスミン初期
  3. jquery と jasmine-jquery をヘルパー フォルダーに追加します。
  4. ここに私のリポジトリがあります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 で動作させる方法について何か不足していますか? ありがとう、アンドリュー

4

1 に答える 1

3

私は jasmine jquery を維持しています。数分前に jasmine v2 のサポートを追加しました。https://github.com/velesin/jasmine-jquery/

于 2014-01-13T23:45:24.473 に答える