【发布时间】:2015-12-11 03:58:26
【问题描述】:
我在我的 AngularJS 量角器测试中添加了一个模拟模块,但它似乎没有被选中。 api 调用直接转到真正的 api。此外,当我执行 console.log(browser) 时,我确实看到了:
名称:'httpBackendMock',脚本:[Function],参数:[]}
httpBackendMock 中没有任何 console.log 语句被触发。
describe('successful login', function(done) {
var httpBackendMock = function() {
angular.module('httpBackendMock', ['ngMockE2E', 'sampleapp']).run(function($httpBackend) {
var authenticated = false;
var testAccount = {
email: 'test@example.com'
};
$httpBackend.whenPOST('/login').respond(function(method, url, data, headers) {
console.log(data);
console.log("executing");
return [200, {loggedIn: true}, {}];
});
$httpBackend.whenGET(/.*/).passThrough();
})
};
beforeEach(function(){
browser.addMockModule('httpBackendMock', httpBackendMock);
});
it('should login', function(done) {
console.log(httpBackendMock.toString());
console.log(browser);
var url = browser.getCurrentUrl();
element(by.id('user-input')).sendKeys('someuser');
element(by.id('password-input')).sendKeys('somepassword');
element(by.css('.btn-default')).click();
expect(browser.getCurrentUrl()).toNotBe(url);
expect(browser.getCurrentUrl()).toContain('account-page');
done();
});
});
【问题讨论】:
标签: angularjs jasmine protractor