angular-cn/packages/compiler/testing/src/pipe_resolver_mock.ts

35 lines
1000 B
TypeScript
Raw Normal View History

2016-07-28 09:40:50 -04:00
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {CompileReflector, PipeResolver, core} from '@angular/compiler';
2016-07-28 09:40:50 -04:00
export class MockPipeResolver extends PipeResolver {
private _pipes = new Map<core.Type, core.Pipe>();
2016-07-28 09:40:50 -04:00
constructor(refector: CompileReflector) { super(refector); }
2016-07-28 09:40:50 -04:00
/**
* Overrides the {@link Pipe} for a pipe.
2016-07-28 09:40:50 -04:00
*/
setPipe(type: core.Type, metadata: core.Pipe): void { this._pipes.set(type, metadata); }
2016-07-28 09:40:50 -04:00
/**
* Returns the {@link Pipe} for a pipe:
* - Set the {@link Pipe} to the overridden view when it exists or fallback to the
2016-07-28 09:40:50 -04:00
* default
* `PipeResolver`, see `setPipe`.
*/
resolve(type: core.Type, throwIfNotFound = true): core.Pipe {
let metadata = this._pipes.get(type);
2016-07-28 09:40:50 -04:00
if (!metadata) {
metadata = super.resolve(type, throwIfNotFound) !;
2016-07-28 09:40:50 -04:00
}
return metadata;
}
}