Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(jasmine): Update Jasmine to support Node8 async/await (#4608)
Browse files Browse the repository at this point in the history
Breaking change for TypeScript:

JasmineWD doesn't know anything about async/await, turns off JasmineWD if control flow was disabled.

It will affect TypeScript tests that are using async/await and
1. miss some await keyword in the test.(Previously, this might cause the
test failed silently and be reported as pass), or
2. use Promise in jasmine expect function

Before
```ts
await expect(getPromise()).toEqual(42);
```

After
```ts
expect(await getPromise()).toEqual(42);
```
  • Loading branch information
qiyigg committed Dec 1, 2017
1 parent 1b486a2 commit 5d13b00
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
6 changes: 5 additions & 1 deletion lib/frameworks/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ exports.run = function(runner, specs) {
var jrunner = new JasmineRunner();
/* global jasmine */

require('jasminewd2').init(webdriver.promise.controlFlow(), webdriver);
// Don't even require JasmineWD if the control
// flow is turned off.
if (webdriver.promise.USE_PROMISE_MANAGER) {
require('jasminewd2').init(webdriver.promise.controlFlow(), webdriver);
}

var jasmineNodeOpts = runner.getConfig().jasmineNodeOpts;

Expand Down
38 changes: 19 additions & 19 deletions spec/ts/basic/element_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ describe('ElementFinder', function() {
await browser.get('index.html#/form');
const nameByElement = element(by.binding('username'));

await expect(nameByElement.getText())
.toEqual(browser.findElement(by.binding('username')).getText());
expect(await nameByElement.getText())
.toEqual(await browser.findElement(by.binding('username')).getText());
});

it('should wait to grab the WebElement until a method is called', async function() {
Expand All @@ -19,11 +19,11 @@ describe('ElementFinder', function() {

await browser.get('index.html#/form');

await expect(name.getText()).toEqual('Anon');
expect(await name.getText()).toEqual('Anon');

await usernameInput.clear();
await usernameInput.sendKeys('Jane');
await expect(name.getText()).toEqual('Jane');
expect(await name.getText()).toEqual('Jane');
});

it('should chain element actions', async function() {
Expand All @@ -32,10 +32,10 @@ describe('ElementFinder', function() {
const usernameInput = element(by.model('username'));
const name = element(by.binding('username'));

await expect(name.getText()).toEqual('Anon');
expect(await name.getText()).toEqual('Anon');

await((usernameInput.clear() as any) as ElementFinder).sendKeys('Jane');
await expect(name.getText()).toEqual('Jane');
expect(await name.getText()).toEqual('Jane');
});

it('should run chained element actions in sequence', function(done: any) {
Expand Down Expand Up @@ -75,8 +75,8 @@ describe('ElementFinder', function() {

await browser.get('index.html#/conflict');

await expect(reused.getText()).toEqual('Inner: inner');
await expect(reused.isPresent()).toBe(true);
expect(await reused.getText()).toEqual('Inner: inner');
expect(await reused.isPresent()).toBe(true);
});

it('should differentiate elements with the same binding by chaining', async function() {
Expand All @@ -85,8 +85,8 @@ describe('ElementFinder', function() {
const outerReused = element(by.binding('item.reusedBinding'));
const innerReused = element(by.id('baz')).element(by.binding('item.reusedBinding'));

await expect(outerReused.getText()).toEqual('Outer: outer');
await expect(innerReused.getText()).toEqual('Inner: inner');
expect(await outerReused.getText()).toEqual('Outer: outer');
expect(await innerReused.getText()).toEqual('Inner: inner');
});

it('should chain deeper than 2', async function() {
Expand All @@ -96,7 +96,7 @@ describe('ElementFinder', function() {

await browser.get('index.html#/conflict');

await expect(reused.getText()).toEqual('Inner: inner');
expect(await reused.getText()).toEqual('Inner: inner');
});

it('should allow handling errors', async function() {
Expand Down Expand Up @@ -129,8 +129,8 @@ describe('ElementFinder', function() {
const byCss = by.css('body');
const byBinding = by.binding('greet');

await expect(element(byCss).locator()).toEqual(byCss);
await expect(element(byBinding).locator()).toEqual(byBinding);
expect(await element(byCss).locator()).toEqual(byCss);
expect(await element(byBinding).locator()).toEqual(byBinding);
});

it('should propagate exceptions', async function() {
Expand All @@ -144,7 +144,7 @@ describe('ElementFinder', function() {
function() {
return false;
} as any as (() => ppromise.Promise<void>));
await expect(successful).toEqual(false);
expect(await successful).toEqual(false);
});

it('should be returned from a helper without infinite loops', async function() {
Expand All @@ -154,7 +154,7 @@ describe('ElementFinder', function() {
});

await helperPromise.then(async function(finalResult: ElementFinder) {
await expect(finalResult.getText()).toEqual('Hiya');
expect(await finalResult.getText()).toEqual('Hiya');
} as any as (() => ppromise.Promise<void>));
});

Expand All @@ -169,8 +169,8 @@ describe('ElementFinder', function() {

const name = element(by.binding('username'));

await expect(name.getText()).toEqual('Anon');
await expect(name.getText().then(null, function() {})).toEqual('Anon');
expect(await name.getText()).toEqual('Anon');
expect(await name.getText().then(null, function() {})).toEqual('Anon');

});

Expand All @@ -180,7 +180,7 @@ describe('ElementFinder', function() {
const usernameInput = element(by.model('username'));
const name = element(by.binding('username'));

await expect(usernameInput.equals(usernameInput)).toEqual(true);
await expect(usernameInput.equals(name)).toEqual(false);
expect(await usernameInput.equals(usernameInput)).toEqual(true);
expect(await usernameInput.equals(name)).toEqual(false);
});
});
2 changes: 1 addition & 1 deletion spec/ts/plugin/plugin_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import {browser, protractor} from '../../..';
describe('plugins', function() {
it('should have run the onPageLoad hook', async function() {
await browser.get('index.html');
await expect((protractor as any).ON_PAGE_LOAD).toBe(true);
expect(await (protractor as any).ON_PAGE_LOAD).toBe(true);
});
});

0 comments on commit 5d13b00

Please sign in to comment.