2

分度器をライブラリとして使用する

Jasmine への参照を要求できません。expectメソッドを参照するとoutput が返されますCannot call method 'expect' of null

コメントを反映するために更新されたコード:

var protractor = require('protractor');
require('protractor/node_modules/minijasminenode');
require('protractor/jasminewd'); // output: jasmine is undefined (this error can only be seen if the above line is commented out)
//expect(true).toBe(true); // output: Cannot call method 'expect' of null

var driver = new protractor.Builder()
    .usingServer('http://localhost:4444/wd/hub')
    .withCapabilities(protractor.Capabilities
    .chrome()).build();

var ptor = protractor.wrapDriver(driver);

ptor.get('http://www.angularjs.org').then(function(){
    ptor.element(protractor.By.model('yourName')).sendKeys('test')
        .then(console.log('success')); // output: success
        ptor.getCurrentUrl().then(function(url){
            console.log(url); // output: http://www.angularjs.org
            expect(url).toContain('angular'); // output: Cannot call method 'expect' of null
        });
});

関連情報については、 https://github.com/angular/protractor/issues/21を参照してください。

4

2 に答える 2

1

jasmine の it 関数コンテキストに入るたびに、グローバルな jasmine expect 関数が新しく生成されます。

それはあなたのコードにとって何を意味しますか? it 関数の外で expect を呼び出すことはできません。

例:

...
  // somewhere in your code
...
  // function expect doesn’t exist here
describe( 'your case', function() {
    // expect doesn’t exist here either
  it( 'should work', function() {
    // horray - the global expect is available !!
    // note : the expect function is generated before running your callback 
    // function to collect the expect'ed results for exactly this 'it' case
      expect( true).toBe( true); 
  });
})
于 2014-05-05T17:22:17.580 に答える
0

Julie のこの投稿を引用します。

Jasmine が非同期テストを自動的に理解できるようにするには、jasmine-wd アダプターを次のように要求する必要があります。

require('protractor/jasminewd');

(上記の行を の直後に追加するだけ... = require('protractor');です。)

于 2014-01-07T19:15:24.853 に答える