Angular/Jasmine:$httpBackend.expectGET 适用于 Mac,不适用于 Linux
Angular/Jasmine: $httpBackend.expectGET works on Mac, not on Linux
我有以下设置来测试指令:
beforeEach(inject(function($compile, $rootScope, $injector) {
$httpBackend = $injector.get('$httpBackend');
var html = '<password-strength-bar password-to-check="password"></password-strength-bar>';
scope = $rootScope.$new();
elm = angular.element(html);
$compile(elm)(scope);
$httpBackend.expectGET('l10n/en.js').respond({});
$httpBackend.expectGET('tpl/page_signin.html').respond({});
}));
这在 Mac 上运行良好。但是,当我 运行 Linux 上的相同代码时,它失败并出现以下错误。这是一个无头的 Linux 盒子,但我在 karma.conf.js
.
中使用 PhantomJS 作为我的 "browsers"
Error: Unsatisfied requests: GET tpl/page_signin.html
我确认两个操作系统都使用相同版本的 Node。
类似地,我已经安装了 Chrome 和 Xfvb(通过 Jenkins)到 运行 我的量角器驱动的 e2e 测试。当 运行 在我的本地 Mac 上运行时,以下工作正常,但在 Linux.
上失败
it('should render signup when user clicks on "Create one" link', function () {
var signupLink = element(by.linkText('Create one'));
expect(signupLink.isDisplayed()).toBe(true);
signupLink.click();
expect(element.all(by.css('.wrapper')).first().getText()).
toMatch(/Hi there, we're so glad you're here./);
在 Jenkins 中(在 Linux 上),错误是:
Failures:
1) account signup should render signup when user clicks on "Create one" link
Message:
[31m Expected '' to match /Hi there, we're so glad you're here./.[0m
Stack:
Error: Failed expectation
at Object.<anonymous> (/var/lib/jenkins/jobs/myapp/workspace/tests/e2e/account.js:27:17)
at runMicrotasksCallback (node.js:337:7)
知道为什么测试 运行 在 Mac 上没问题,但在 Linux 上不行吗?
原来是因为我的 Protractor 测试使用了 by.linkText('Create one')。一旦我将 id 添加到 link 并使用 by.id('create-account'),它就起作用了。
我还发现使用 $('.alert') 或 by.css('alert') 的效果几乎不如 by.id。特别是当您单击一个按钮并等待下一个屏幕上出现某些内容时。例如:
var alert = element(by.id('success'));
browser.driver.wait(protractor.until.elementIsVisible(alert));
我有以下设置来测试指令:
beforeEach(inject(function($compile, $rootScope, $injector) {
$httpBackend = $injector.get('$httpBackend');
var html = '<password-strength-bar password-to-check="password"></password-strength-bar>';
scope = $rootScope.$new();
elm = angular.element(html);
$compile(elm)(scope);
$httpBackend.expectGET('l10n/en.js').respond({});
$httpBackend.expectGET('tpl/page_signin.html').respond({});
}));
这在 Mac 上运行良好。但是,当我 运行 Linux 上的相同代码时,它失败并出现以下错误。这是一个无头的 Linux 盒子,但我在 karma.conf.js
.
Error: Unsatisfied requests: GET tpl/page_signin.html
我确认两个操作系统都使用相同版本的 Node。
类似地,我已经安装了 Chrome 和 Xfvb(通过 Jenkins)到 运行 我的量角器驱动的 e2e 测试。当 运行 在我的本地 Mac 上运行时,以下工作正常,但在 Linux.
上失败it('should render signup when user clicks on "Create one" link', function () {
var signupLink = element(by.linkText('Create one'));
expect(signupLink.isDisplayed()).toBe(true);
signupLink.click();
expect(element.all(by.css('.wrapper')).first().getText()).
toMatch(/Hi there, we're so glad you're here./);
在 Jenkins 中(在 Linux 上),错误是:
Failures:
1) account signup should render signup when user clicks on "Create one" link
Message:
[31m Expected '' to match /Hi there, we're so glad you're here./.[0m
Stack:
Error: Failed expectation
at Object.<anonymous> (/var/lib/jenkins/jobs/myapp/workspace/tests/e2e/account.js:27:17)
at runMicrotasksCallback (node.js:337:7)
知道为什么测试 运行 在 Mac 上没问题,但在 Linux 上不行吗?
原来是因为我的 Protractor 测试使用了 by.linkText('Create one')。一旦我将 id 添加到 link 并使用 by.id('create-account'),它就起作用了。
我还发现使用 $('.alert') 或 by.css('alert') 的效果几乎不如 by.id。特别是当您单击一个按钮并等待下一个屏幕上出现某些内容时。例如:
var alert = element(by.id('success'));
browser.driver.wait(protractor.until.elementIsVisible(alert));