2016-11-18 18:17:44 -05: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 {PipeResolver} from '@angular/compiler/src/pipe_resolver';
|
2017-03-02 12:37:01 -05:00
|
|
|
import {ɵstringify as stringify} from '@angular/core';
|
2016-11-18 18:17:44 -05:00
|
|
|
import {Pipe} from '@angular/core/src/metadata';
|
2017-08-16 12:00:03 -04:00
|
|
|
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
2016-11-18 18:17:44 -05:00
|
|
|
|
|
|
|
@Pipe({name: 'somePipe', pure: true})
|
|
|
|
class SomePipe {
|
|
|
|
}
|
|
|
|
|
|
|
|
class SimpleClass {}
|
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2016-11-18 18:17:44 -05:00
|
|
|
describe('PipeResolver', () => {
|
|
|
|
let resolver: PipeResolver;
|
|
|
|
|
2020-04-08 13:14:18 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
resolver = new PipeResolver(new JitReflector());
|
|
|
|
});
|
2016-11-18 18:17:44 -05:00
|
|
|
|
|
|
|
it('should read out the metadata from the class', () => {
|
|
|
|
const moduleMetadata = resolver.resolve(SomePipe);
|
|
|
|
expect(moduleMetadata).toEqual(new Pipe({name: 'somePipe', pure: true}));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw when simple class has no pipe decorator', () => {
|
|
|
|
expect(() => resolver.resolve(SimpleClass))
|
|
|
|
.toThrowError(`No Pipe decorator found on ${stringify(SimpleClass)}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should support inheriting the metadata', function() {
|
|
|
|
@Pipe({name: 'p'})
|
|
|
|
class Parent {
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChildNoDecorator extends Parent {}
|
|
|
|
|
|
|
|
@Pipe({name: 'c'})
|
|
|
|
class ChildWithDecorator extends Parent {
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(resolver.resolve(ChildNoDecorator)).toEqual(new Pipe({name: 'p'}));
|
|
|
|
|
|
|
|
expect(resolver.resolve(ChildWithDecorator)).toEqual(new Pipe({name: 'c'}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|