angular-docs-cn/modules/angular2/test/pipes/uppercase_pipe_spec.ts
vsavkin 5b5d31fa9a feat(pipe): added the Pipe decorator and the pipe property to View
BREAKING CHANGE:
    Instead of configuring pipes via a Pipes object, now you can configure them by providing the pipes property to the View decorator.

    @Pipe({
      name: 'double'
    })
    class DoublePipe {
      transform(value, args) { return value * 2; }
    }

    @View({
      template: '{{ 10 | double}}'
      pipes: [DoublePipe]
    })
    class CustomComponent {}

Closes #3572
2015-08-12 00:38:40 +00:00

37 lines
913 B
TypeScript

import {ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach} from 'angular2/test_lib';
import {UpperCasePipe} from 'angular2/pipes';
export function main() {
describe("UpperCasePipe", () => {
var upper;
var lower;
var pipe;
beforeEach(() => {
lower = 'something';
upper = 'SOMETHING';
pipe = new UpperCasePipe();
});
describe("transform", () => {
it("should return uppercase", () => {
var val = pipe.transform(lower);
expect(val).toEqual(upper);
});
it("should uppercase when there is a new value", () => {
var val = pipe.transform(lower);
expect(val).toEqual(upper);
var val2 = pipe.transform('wat');
expect(val2).toEqual('WAT');
});
it("should not support other objects",
() => { expect(() => pipe.transform(new Object())).toThrowError(); });
});
});
}