refactor: change provide(...) for {provide: ...}

- provide() is deprecated,
- {} syntax is required by the offline compiler
This commit is contained in:
Victor Berchet
2016-06-02 17:30:40 -07:00
parent 27a47e7841
commit a6ad61d83e
128 changed files with 676 additions and 728 deletions

View File

@ -113,7 +113,7 @@ export function main() {
getDOM().appendChild(el, lightDom);
getDOM().setText(lightDom, 'loading');
testProviders =
[provide(DOCUMENT, {useValue: fakeDoc}), provide(Console, {useClass: DummyConsole})];
[{provide: DOCUMENT, useValue: fakeDoc}, {provide: Console, useClass: DummyConsole}];
});
afterEach(disposePlatform);
@ -123,7 +123,7 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, false);
expect(
() => bootstrap(HelloRootDirectiveIsNotCmp,
[testProviders, provide(ExceptionHandler, {useValue: exceptionHandler})]))
[testProviders, {provide: ExceptionHandler, useValue: exceptionHandler}]))
.toThrowError(
`Could not compile '${stringify(HelloRootDirectiveIsNotCmp)}' because it is not a component.`);
expect(logger.res.join("")).toContain("Could not compile");
@ -134,7 +134,7 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, false);
var refPromise =
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
PromiseWrapper.then(refPromise, null, (reason) => {
expect(reason.message).toContain('The selector "hello-app" did not match any elements');
async.done();
@ -150,7 +150,7 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, false);
var refPromise =
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
PromiseWrapper.then(refPromise, null, (reason: any) => {
expect(reason.message)
.toContain('The selector "hello-app" did not match any elements');
@ -164,7 +164,7 @@ export function main() {
var exceptionHandler = new ExceptionHandler(logger, false);
var refPromise =
bootstrap(HelloRootCmp, [provide(ExceptionHandler, {useValue: exceptionHandler})]);
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
PromiseWrapper.then(refPromise, null, (reason) => {
expect(logger.res.join(""))
.toContain('The selector "hello-app" did not match any elements');
@ -225,7 +225,7 @@ export function main() {
it("should make the provided bindings available to the application component",
inject([AsyncTestCompleter], (async) => {
var refPromise = bootstrap(
HelloRootCmp3, [testProviders, provide("appBinding", {useValue: "BoundValue"})]);
HelloRootCmp3, [testProviders, {provide: "appBinding", useValue: "BoundValue"}]);
refPromise.then((ref) => {
expect(ref.instance.appBinding).toEqual("BoundValue");
@ -246,16 +246,16 @@ export function main() {
it("should run platform initializers", inject([Log], (log: Log) => {
let p = createPlatform(ReflectiveInjector.resolveAndCreate([
BROWSER_PLATFORM_PROVIDERS,
provide(PLATFORM_INITIALIZER, {useValue: log.fn("platform_init1"), multi: true}),
provide(PLATFORM_INITIALIZER, {useValue: log.fn("platform_init2"), multi: true})
{provide: PLATFORM_INITIALIZER, useValue: log.fn("platform_init1"), multi: true},
{provide: PLATFORM_INITIALIZER, useValue: log.fn("platform_init2"), multi: true}
]));
expect(log.result()).toEqual("platform_init1; platform_init2");
log.clear();
var a = ReflectiveInjector.resolveAndCreate(
[
BROWSER_APP_PROVIDERS,
provide(APP_INITIALIZER, {useValue: log.fn("app_init1"), multi: true}),
provide(APP_INITIALIZER, {useValue: log.fn("app_init2"), multi: true})
{provide: APP_INITIALIZER, useValue: log.fn("app_init1"), multi: true},
{provide: APP_INITIALIZER, useValue: log.fn("app_init2"), multi: true}
],
p.injector);
a.get(ApplicationRef);

View File

@ -16,7 +16,7 @@ class SpyComponentRef extends SpyObject implements ComponentRef<dynamic> {
SpyComponentRef() {
this.injector = ReflectiveInjector
.resolveAndCreate([bind(ApplicationRef).toClass(SpyApplicationRef)]);
.resolveAndCreate([{provide: ApplicationRef, useClass: SpyApplicationRef}]);
}
}

View File

@ -12,7 +12,7 @@ export class SpyComponentRef extends SpyObject {
constructor() {
super();
this.injector = ReflectiveInjector.resolveAndCreate(
[provide(ApplicationRef, {useClass: SpyApplicationRef})]);
[{provide: ApplicationRef, useClass: SpyApplicationRef}]);
}
}

View File

@ -120,7 +120,7 @@ export function main() {
describe('using the test injector with the inject helper', () => {
describe('setting up Providers', () => {
beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]);
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
it('provides a real XHR instance',
inject([XHR], (xhr) => { expect(xhr).toBeAnInstanceOf(XHRImpl); }));

View File

@ -134,7 +134,7 @@ export function main() {
describe('using the test injector with the inject helper', () => {
describe('setting up Providers', () => {
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
it('should use set up providers',
inject([FancyService], (service) => { expect(service.value).toEqual('real value'); }));
@ -185,12 +185,12 @@ export function main() {
describe('per test providers', () => {
it('should allow per test providers',
withProviders(() => [provide(FancyService, {useValue: new FancyService()})])
withProviders(() => [{provide: FancyService, useValue: new FancyService()}])
.inject([FancyService],
(service) => { expect(service.value).toEqual('real value'); }));
it('should return value from inject', () => {
let retval = withProviders(() => [provide(FancyService, {useValue: new FancyService()})])
let retval = withProviders(() => [{provide: FancyService, useValue: new FancyService()}])
.inject([FancyService], (service) => {
expect(service.value).toEqual('real value');
return 10;
@ -265,7 +265,7 @@ export function main() {
});
describe('using beforeEachProviders', () => {
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
beforeEach(
inject([FancyService], (service) => { expect(service.value).toEqual('real value'); }));
@ -275,7 +275,7 @@ export function main() {
it('should fail when the injector has already been used', () => {
patchJasmineBeforeEach();
expect(() => {
beforeEachProviders(() => [provide(FancyService, {useValue: new FancyService()})]);
beforeEachProviders(() => [{provide: FancyService, useValue: new FancyService()}]);
})
.toThrowError('beforeEachProviders was called after the injector had been used ' +
'in a beforeEach or it block. This invalidates the test injector');
@ -364,7 +364,7 @@ export function main() {
it('should override a provider',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.overrideProviders(TestProvidersComp, [provide(FancyService, {useClass: MockFancyService})])
tcb.overrideProviders(TestProvidersComp, [{provide: FancyService, useClass: MockFancyService}])
.createAsync(TestProvidersComp)
.then((componentFixture) => {
componentFixture.detectChanges();
@ -378,7 +378,7 @@ export function main() {
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
tcb.overrideViewProviders(TestViewProvidersComp,
[provide(FancyService, {useClass: MockFancyService})])
[{provide: FancyService, useClass: MockFancyService}])
.createAsync(TestViewProvidersComp)
.then((componentFixture) => {
componentFixture.detectChanges();

View File

@ -112,7 +112,7 @@ export function main() {
function flushMessages(fn: () => void) { TimerWrapper.setTimeout(fn, 50); }
it("should buffer messages and wait for the zone to exit before sending",
withProviders(() => [provide(NgZone, {useClass: MockNgZone})])
withProviders(() => [{provide: NgZone, useClass: MockNgZone}])
.inject([AsyncTestCompleter, NgZone],
(async, zone: MockNgZone) => {
bus = createConnectedMessageBus();

View File

@ -27,7 +27,7 @@ export function main() {
const RESULT = 20;
const ID = "methodId";
beforeEachProviders(() => [Serializer, provide(ON_WEB_WORKER, {useValue: true}), RenderStore]);
beforeEachProviders(() => [Serializer, {provide: ON_WEB_WORKER, useValue: true}, RenderStore]);
describe("UIMessageBroker", () => {
var messageBuses;

View File

@ -86,9 +86,9 @@ export function main() {
testUiInjector.applicationProviders = TEST_BROWSER_APPLICATION_PROVIDERS;
testUiInjector.addProviders([
Serializer,
provide(RenderStore, {useValue: uiRenderStore}),
provide(DomRootRenderer, {useClass: DomRootRenderer_}),
provide(RootRenderer, {useExisting: DomRootRenderer})
{provide: RenderStore, useValue: uiRenderStore},
{provide: DomRootRenderer, useClass: DomRootRenderer_},
{provide: RootRenderer, useExisting: DomRootRenderer}
]);
uiInjector = testUiInjector.createInjector();
var uiSerializer = uiInjector.get(Serializer);
@ -96,16 +96,16 @@ export function main() {
workerRenderStore = new RenderStore();
return [
Serializer,
provide(CompilerConfig, {useValue: new CompilerConfig(true, true, false)}),
provide(RenderStore, {useValue: workerRenderStore}),
provide(RootRenderer,
{
useFactory: (workerSerializer) => {
return createWorkerRenderer(workerSerializer, uiSerializer, domRootRenderer,
uiRenderStore, workerRenderStore);
},
deps: [Serializer]
})
{provide: CompilerConfig, useValue: new CompilerConfig(true, true, false)},
{provide: RenderStore, useValue: workerRenderStore},
{
provide: RootRenderer,
useFactory: (workerSerializer) => {
return createWorkerRenderer(workerSerializer, uiSerializer, domRootRenderer,
uiRenderStore, workerRenderStore);
},
deps: [Serializer]
}
];
});

View File

@ -32,8 +32,8 @@ export function main() {
return new CachedXHR();
}
beforeEachProviders(() => [
provide(UrlResolver, {useClass: TestUrlResolver}),
provide(XHR, {useFactory: createCachedXHR})
{provide: UrlResolver, useClass: TestUrlResolver},
{provide: XHR, useFactory: createCachedXHR}
]);
it('should throw exception if $templateCache is not found', () => {