angular-docs-cn/modules/benchpress/test/web_driver_extension_spec.ts
Tobias Bosch 0a7d10ba55 refactor(core): separate reflective injector from Injector interface
BREAKING CHANGE:
- Injector was renamed into `ReflectiveInjector`,
  as `Injector` is only an abstract class with one method on it
- `Injector.getOptional()` was changed into `Injector.get(token, notFoundValue)`
  to make implementing injectors simpler
- `ViewContainerRef.createComponent` now takes an `Injector`
  instead of `ResolvedProviders`. If a reflective injector
  should be used, create one before calling this method.
  (e.g. via `ReflectiveInjector.resolveAndCreate(…)`.
2016-04-20 11:28:13 -07:00

63 lines
1.7 KiB
TypeScript

import {
afterEach,
AsyncTestCompleter,
beforeEach,
ddescribe,
describe,
expect,
iit,
inject,
it,
xit,
} from 'angular2/testing_internal';
import {isPresent, StringWrapper} from 'angular2/src/facade/lang';
import {PromiseWrapper} from 'angular2/src/facade/async';
import {WebDriverExtension, bind, provide, ReflectiveInjector, Options} from 'benchpress/common';
export function main() {
function createExtension(ids: any[], caps) {
return PromiseWrapper.wrap(() => {
return ReflectiveInjector.resolveAndCreate([
ids.map(id => provide(id, {useValue: new MockExtension(id)})),
bind(Options.CAPABILITIES).toValue(caps),
WebDriverExtension.bindTo(ids)
])
.get(WebDriverExtension);
});
}
describe('WebDriverExtension.bindTo', () => {
it('should bind the extension that matches the capabilities',
inject([AsyncTestCompleter], (async) => {
createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'})
.then((m) => {
expect(m.id).toEqual('m2');
async.done();
});
}));
it('should throw if there is no match', inject([AsyncTestCompleter], (async) => {
PromiseWrapper.catchError(createExtension(['m1'], {'browser': 'm2'}), (err) => {
expect(isPresent(err)).toBe(true);
async.done();
});
}));
});
}
class MockExtension extends WebDriverExtension {
id: string;
constructor(id) {
super();
this.id = id;
}
supports(capabilities: {[key: string]: any}): boolean {
return StringWrapper.equals(capabilities['browser'], this.id);
}
}