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

Commit

Permalink
fix(jasminewd): allow asynchronous callbacks for jasmine tests
Browse files Browse the repository at this point in the history
Closes #728, Closes #704
  • Loading branch information
hankduan authored and juliemr committed Apr 25, 2014
1 parent 35dcea0 commit 43ff9e5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
21 changes: 17 additions & 4 deletions jasminewd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,25 @@ function wrapInControlFlow(globalFn, fnName) {
}
desc_ += ')';

// deferred object for signaling completion of asychronous function within globalFn
var asyncFnDone = webdriver.promise.defer();

if (fn.length == 0) {
// function with globalFn not asychronous
asyncFnDone.fulfill();
} else if (fn.length > 1) {
throw Error('Invalid # arguments (' + fn.length + ') within function "' + fnName +'"');
}

flow.execute(function() {
fn.call(jasmine.getEnv().currentSpec, function() {
throw new Error('Do not use a done callback with WebDriverJS tests. ' +
'The tests are patched to be asynchronous and will terminate when ' +
'the webdriver control flow is empty.');
fn.call(jasmine.getEnv().currentSpec, function(userError) {
if (userError) {
asyncFnDone.reject(new Error(userError));
} else {
asyncFnDone.fulfill();
}
});
return asyncFnDone.promise;
}, desc_).then(seal(done), function(e) {
e.stack = e.stack + '==== async task ====\n' + driverError.stack;
done(e);
Expand Down
27 changes: 25 additions & 2 deletions jasminewd/spec/adapterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,34 @@ describe('webdriverJS Jasmine adapter', function() {
// expect(fakeDriver.getValueB()).toEqual('b');
// }, 300);

// it('should error with a warning if done callback is used', function(done) {
// done();
// it('should pass errors from done callback', function(done) {
// done('an error');
// });

it('should pass after the timed out tests', function() {
expect(true).toEqual(true);
});

describe('should work for both synchronous and asynchronous tests', function() {
var x;

beforeEach(function() {
x = 0;
});

afterEach(function() {
expect(x).toBe(1);
});

it('should execute a synchronous test', function() {
x = 1;
});

it('should execute an asynchronous test', function(done) {
setTimeout(function(){
x = 1;
done();
}, 500);
});
});
});

4 comments on commit 43ff9e5

@smahalingam
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have async call inside the "it" and that is never been executed. Can you point me what's wrong in the below code please?

describe('vCDBubble', function() {
it('Check Org exists on the vCD', function(done) {

console.log("Ourside the async");
setTimeout(function(){
  x = 1;
  console.log("Inside the async");
  done();
}, 500);

});

});

@elgalu
Copy link
Contributor

@elgalu elgalu commented on 43ff9e5 May 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smahalingam what version of protractor are you using?

@smahalingam
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elgalu - Thanks for your reply and helping me on this. I am using version 20.
Ss-MacBook-Air:~ smahalingam$
Ss-MacBook-Air:~ smahalingam$ protractor --version
Version 0.22.0
Ss-MacBook-Air:~ smahalingam$

I am happy to give you more info, if required. Thanks in advance.

@elgalu
Copy link
Contributor

@elgalu elgalu commented on 43ff9e5 May 10, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're welcome @smahalingam !!
The thing is that this commit is only on master for now, so won't be available until protractor version >= 0.23.0

Please sign in to comment.