angular-cn/modules/angular2/test/common/pipes/i18n_plural_pipe_spec.ts
Tobias Bosch 152a117d5c fix(compiler): properly implement pure pipes and change pipe syntax
Pure pipes as well as arrays and maps are
implemented via proxy functions. This is
faster than the previous implementation
and also generates less code.

BREAKING CHANGE:
- pipes now take a variable number of arguments, and not an array that contains all arguments.
2016-04-25 09:04:22 -07:00

60 lines
1.8 KiB
TypeScript

import {
ddescribe,
describe,
it,
iit,
xit,
expect,
beforeEach,
afterEach
} from 'angular2/testing_internal';
import {I18nPluralPipe} from 'angular2/common';
import {PipeResolver} from 'angular2/src/compiler/pipe_resolver';
export function main() {
describe("I18nPluralPipe", () => {
var pipe;
var mapping = {'=0': 'No messages.', '=1': 'One message.', 'other': 'There are some messages.'};
var interpolatedMapping =
{'=0': 'No messages.', '=1': 'One message.', 'other': 'There are # messages, that is #.'};
beforeEach(() => { pipe = new I18nPluralPipe(); });
it('should be marked as pure',
() => { expect(new PipeResolver().resolve(I18nPluralPipe).pure).toEqual(true); });
describe("transform", () => {
it("should return 0 text if value is 0", () => {
var val = pipe.transform(0, mapping);
expect(val).toEqual('No messages.');
});
it("should return 1 text if value is 1", () => {
var val = pipe.transform(1, mapping);
expect(val).toEqual('One message.');
});
it("should return other text if value is anything other than 0 or 1", () => {
var val = pipe.transform(6, mapping);
expect(val).toEqual('There are some messages.');
});
it("should interpolate the value into the text where indicated", () => {
var val = pipe.transform(6, interpolatedMapping);
expect(val).toEqual('There are 6 messages, that is 6.');
});
it("should use 'other' if value is undefined", () => {
var messageLength;
var val = pipe.transform(messageLength, interpolatedMapping);
expect(val).toEqual('There are messages, that is .');
});
it("should not support bad arguments",
() => { expect(() => pipe.transform(0, 'hey')).toThrowError(); });
});
});
}