Skip to content

Commit 65ebff0

Browse files
committed
refactor(benchpress): make tests for error cases also work in Dart
Also introduces `PromiseWrapper.catchError`. Could not use `PromiseWrapper.catch` as a name as Dart would not allow this method name.
1 parent dd1898c commit 65ebff0

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

modules/angular2/src/facade/async.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class PromiseWrapper {
1515
return promise.then(success, onError: onError);
1616
}
1717

18+
// Note: We can't rename this method to `catch`, as this is not a valid
19+
// method name in Dart.
20+
static Future catchError(Future promise, Function onError) {
21+
return promise.catchError(onError);
22+
}
23+
1824
static _Completer completer() => new _Completer(new Completer());
1925

2026
static void setTimeout(fn(), int millis) {

modules/angular2/src/facade/async.es6

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export class PromiseWrapper {
1212
return Promise.reject(obj);
1313
}
1414

15+
// Note: We can't rename this method into `catch`, as this is not a valid
16+
// method name in Dart.
17+
static catchError(promise:Promise, onError:Function):Promise {
18+
return promise.catch(onError);
19+
}
20+
1521
static all(promises:List):Promise {
1622
if (promises.length == 0) return Promise.resolve([]);
1723
return Promise.all(promises);

modules/benchpress/test/web_driver_extension_spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
22

33
import { StringMap, ListWrapper } from 'angular2/src/facade/collection';
4-
import { isPresent, StringWrapper, isJsObject } from 'angular2/src/facade/lang';
4+
import { isPresent, StringWrapper } from 'angular2/src/facade/lang';
5+
import { PromiseWrapper } from 'angular2/src/facade/async';
56

67
import { WebDriverExtension, bind, Injector, Options } from 'benchpress/benchpress';
78

@@ -23,16 +24,15 @@ export function main() {
2324
});
2425
});
2526

26-
// TODO(tbosch): In Dart, somehow we don't provide the error
27-
// correctly in the promise result...
28-
if (isJsObject({})) {
29-
it('should throw if there is no match', (done) => {
30-
createExtension(['m1'], {'browser': 'm2'}).then(null, (err) => {
27+
it('should throw if there is no match', (done) => {
28+
PromiseWrapper.catchError(
29+
createExtension(['m1'], {'browser': 'm2'}),
30+
(err) => {
3131
expect(isPresent(err)).toBe(true);
3232
done();
33-
});
34-
});
35-
}
33+
}
34+
);
35+
});
3636

3737
});
3838
}

modules/benchpress/test/webdriver/chrome_driver_extension_spec.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/te
22

33
import { ListWrapper } from 'angular2/src/facade/collection';
44
import { PromiseWrapper } from 'angular2/src/facade/async';
5-
import { Json, isBlank, isJsObject } from 'angular2/src/facade/lang';
5+
import { Json, isBlank } from 'angular2/src/facade/lang';
66

77
import {
88
WebDriverExtension, ChromeDriverExtension,
@@ -164,20 +164,16 @@ export function main() {
164164
});
165165
});
166166

167-
// TODO(tbosch): In Dart, somehow we don't provide the error
168-
// correctly in the promise result...
169-
if (isJsObject({})) {
170-
it('should throw an error on buffer overflow', (done) => {
171-
createExtension([
172-
chromeTimelineEvents.start('FunctionCall', 1234),
173-
], 'Tracing.bufferUsage').readPerfLog().then(null, (err) => {
174-
expect( () => {
175-
throw err;
176-
}).toThrowError('The DevTools trace buffer filled during the test!');
177-
done();
178-
});
167+
it('should throw an error on buffer overflow', (done) => {
168+
PromiseWrapper.catchError(createExtension([
169+
chromeTimelineEvents.start('FunctionCall', 1234),
170+
], 'Tracing.bufferUsage').readPerfLog(), (err) => {
171+
expect( () => {
172+
throw err;
173+
}).toThrowError('The DevTools trace buffer filled during the test!');
174+
done();
179175
});
180-
}
176+
});
181177

182178
it('should match chrome browsers', () => {
183179
expect(createExtension().supports({

0 commit comments

Comments
 (0)