We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
number-to-zh.pipe.ts
import { Pipe, PipeTransform } from "@angular/core"; @Pipe({name: 'numberToZh'}) export class numberToZhPipe implements PipeTransform { transform(value: any, ...args: any[]) { switch(value) { case '1': return '一'; case '2': return '二'; case '3': return '三'; default: throw new Error(`无效状态码${value}`); } } }
将管道在模块中注册下
import { numberToZhPipe } from "./number-to-zh.pipe"; @NgModule({ ... declarations: [numberToZhPipe], }) export class AppModule {}
然后给其写单元测试
import { numberToZhPipe } from './number-to-zh.pipe'; const pipe = new numberToZhPipe(); it('转换管道应该被创建', ()=>{ expect(pipe).not.toBeUndefined(); }) it('1应该返回一', ()=>{ expect(pipe.transform('1')).toEqual('一'); }) it('2应该返回二', ()=>{ expect(pipe.transform('2')).toEqual('二'); }) it('3应该返回三', ()=>{ expect(pipe.transform('3')).toEqual('三'); })
The text was updated successfully, but these errors were encountered:
No branches or pull requests
单元测试案例
管道
number-to-zh.pipe.ts
将管道在模块中注册下
然后给其写单元测试
The text was updated successfully, but these errors were encountered: