当使用量angular器作为一个库时,'没有方法期待'

使用量angular器作为图书馆

无法要求参考茉莉花。 引用expect方法返回输出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 。

全球茉莉花期待function是每当您踏入茉莉花function环境时新产生的。

这对你的代码意味着什么? 你不能在期望的function之外调用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); }); }) 

引用这个朱莉的post

为了让茉莉花自动理解asynchronoustesting,您需要使用jasmine-wd适配器:

 require('protractor/jasminewd'); 

(只需在... = require('protractor'); )后添加上面的行即可)