This repository was archived by the owner on Jul 29, 2024. It is now read-only.
File tree 2 files changed +42
-6
lines changed
2 files changed +42
-6
lines changed Original file line number Diff line number Diff line change @@ -80,12 +80,25 @@ function wrapInControlFlow(globalFn, fnName) {
80
80
}
81
81
desc_ += ')' ;
82
82
83
+ // deferred object for signaling completion of asychronous function within globalFn
84
+ var asyncFnDone = webdriver . promise . defer ( ) ;
85
+
86
+ if ( fn . length == 0 ) {
87
+ // function with globalFn not asychronous
88
+ asyncFnDone . fulfill ( ) ;
89
+ } else if ( fn . length > 1 ) {
90
+ throw Error ( 'Invalid # arguments (' + fn . length + ') within function "' + fnName + '"' ) ;
91
+ }
92
+
83
93
flow . execute ( function ( ) {
84
- fn . call ( jasmine . getEnv ( ) . currentSpec , function ( ) {
85
- throw new Error ( 'Do not use a done callback with WebDriverJS tests. ' +
86
- 'The tests are patched to be asynchronous and will terminate when ' +
87
- 'the webdriver control flow is empty.' ) ;
94
+ fn . call ( jasmine . getEnv ( ) . currentSpec , function ( userError ) {
95
+ if ( userError ) {
96
+ asyncFnDone . reject ( new Error ( userError ) ) ;
97
+ } else {
98
+ asyncFnDone . fulfill ( ) ;
99
+ }
88
100
} ) ;
101
+ return asyncFnDone . promise ;
89
102
} , desc_ ) . then ( seal ( done ) , function ( e ) {
90
103
e . stack = e . stack + '==== async task ====\n' + driverError . stack ;
91
104
done ( e ) ;
Original file line number Diff line number Diff line change @@ -186,11 +186,34 @@ describe('webdriverJS Jasmine adapter', function() {
186
186
// expect(fakeDriver.getValueB()).toEqual('b');
187
187
// }, 300);
188
188
189
- // it('should error with a warning if done callback is used ', function(done) {
190
- // done();
189
+ // it('should pass errors from done callback', function(done) {
190
+ // done('an error' );
191
191
// });
192
192
193
193
it ( 'should pass after the timed out tests' , function ( ) {
194
194
expect ( true ) . toEqual ( true ) ;
195
195
} ) ;
196
+
197
+ describe ( 'should work for both synchronous and asynchronous tests' , function ( ) {
198
+ var x ;
199
+
200
+ beforeEach ( function ( ) {
201
+ x = 0 ;
202
+ } ) ;
203
+
204
+ afterEach ( function ( ) {
205
+ expect ( x ) . toBe ( 1 ) ;
206
+ } ) ;
207
+
208
+ it ( 'should execute a synchronous test' , function ( ) {
209
+ x = 1 ;
210
+ } ) ;
211
+
212
+ it ( 'should execute an asynchronous test' , function ( done ) {
213
+ setTimeout ( function ( ) {
214
+ x = 1 ;
215
+ done ( ) ;
216
+ } , 500 ) ;
217
+ } ) ;
218
+ } ) ;
196
219
} ) ;
You can’t perform that action at this time.
0 commit comments