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.
This commit is contained in:
parent
dd1898c132
commit
65ebff056a
|
@ -15,6 +15,12 @@ class PromiseWrapper {
|
|||
return promise.then(success, onError: onError);
|
||||
}
|
||||
|
||||
// Note: We can't rename this method to `catch`, as this is not a valid
|
||||
// method name in Dart.
|
||||
static Future catchError(Future promise, Function onError) {
|
||||
return promise.catchError(onError);
|
||||
}
|
||||
|
||||
static _Completer completer() => new _Completer(new Completer());
|
||||
|
||||
static void setTimeout(fn(), int millis) {
|
||||
|
|
|
@ -12,6 +12,12 @@ export class PromiseWrapper {
|
|||
return Promise.reject(obj);
|
||||
}
|
||||
|
||||
// Note: We can't rename this method into `catch`, as this is not a valid
|
||||
// method name in Dart.
|
||||
static catchError(promise:Promise, onError:Function):Promise {
|
||||
return promise.catch(onError);
|
||||
}
|
||||
|
||||
static all(promises:List):Promise {
|
||||
if (promises.length == 0) return Promise.resolve([]);
|
||||
return Promise.all(promises);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
|
||||
|
||||
import { StringMap, ListWrapper } from 'angular2/src/facade/collection';
|
||||
import { isPresent, StringWrapper, isJsObject } from 'angular2/src/facade/lang';
|
||||
import { isPresent, StringWrapper } from 'angular2/src/facade/lang';
|
||||
import { PromiseWrapper } from 'angular2/src/facade/async';
|
||||
|
||||
import { WebDriverExtension, bind, Injector, Options } from 'benchpress/benchpress';
|
||||
|
||||
|
@ -23,16 +24,15 @@ export function main() {
|
|||
});
|
||||
});
|
||||
|
||||
// TODO(tbosch): In Dart, somehow we don't provide the error
|
||||
// correctly in the promise result...
|
||||
if (isJsObject({})) {
|
||||
it('should throw if there is no match', (done) => {
|
||||
createExtension(['m1'], {'browser': 'm2'}).then(null, (err) => {
|
||||
it('should throw if there is no match', (done) => {
|
||||
PromiseWrapper.catchError(
|
||||
createExtension(['m1'], {'browser': 'm2'}),
|
||||
(err) => {
|
||||
expect(isPresent(err)).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import {describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/te
|
|||
|
||||
import { ListWrapper } from 'angular2/src/facade/collection';
|
||||
import { PromiseWrapper } from 'angular2/src/facade/async';
|
||||
import { Json, isBlank, isJsObject } from 'angular2/src/facade/lang';
|
||||
import { Json, isBlank } from 'angular2/src/facade/lang';
|
||||
|
||||
import {
|
||||
WebDriverExtension, ChromeDriverExtension,
|
||||
|
@ -164,20 +164,16 @@ export function main() {
|
|||
});
|
||||
});
|
||||
|
||||
// TODO(tbosch): In Dart, somehow we don't provide the error
|
||||
// correctly in the promise result...
|
||||
if (isJsObject({})) {
|
||||
it('should throw an error on buffer overflow', (done) => {
|
||||
createExtension([
|
||||
chromeTimelineEvents.start('FunctionCall', 1234),
|
||||
], 'Tracing.bufferUsage').readPerfLog().then(null, (err) => {
|
||||
expect( () => {
|
||||
throw err;
|
||||
}).toThrowError('The DevTools trace buffer filled during the test!');
|
||||
done();
|
||||
});
|
||||
it('should throw an error on buffer overflow', (done) => {
|
||||
PromiseWrapper.catchError(createExtension([
|
||||
chromeTimelineEvents.start('FunctionCall', 1234),
|
||||
], 'Tracing.bufferUsage').readPerfLog(), (err) => {
|
||||
expect( () => {
|
||||
throw err;
|
||||
}).toThrowError('The DevTools trace buffer filled during the test!');
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('should match chrome browsers', () => {
|
||||
expect(createExtension().supports({
|
||||
|
|
Loading…
Reference in New Issue