Open DotHide opened 8 years ago
Component decoate 中的变量其实就是类中的一个属性而已
恩 只是不知道怎么去测试或者回避 TypeScript 生成的这些 helper 方法:__decorate
和 __metadata
不做测试的话,跑 coverage 总提示没测到:
----------------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------------------|----------|----------|----------|----------|----------------|
test/ | 89.74 | 48.39 | 80 | 94.29 | |
app.js | 89.66 | 48.28 | 85.71 | 96 | 5 |
当把这些 helper 方法去掉就能跑满 100% ,但由于这些方法的生成不受控制,因此 spec 文件中只能确保自己写的函数经过了测试。所以一直在寻找能测试甚至是回避这些 helper 的方法。
coverage 能 ignore 某些 code么。 可以从这里下手。
这个问题是针对 Ionic2 的,尽管不是纯的 Angular2 问题,但想来它主要基于 Angular2,可能有些共通之处,不知是否能请教一下,举例来说:当我们有个 Home 类,它是这样的:
当我们去写测试的时候,其实类本身没有需要测试的内容,但它的 decorator Component 中有个变量,如果我需要测试,不知这样的测试应该如何去编写?
其实从编译后的结果去观察,它的 js 文件是这样的:
而我的测试文件是这样写的:
因此,每当我跑 code coverage 的时候,总跑不满 100%,发现其中的一个重要原因就是上面这段
__decorate
方法没有被测试到,还望请教一下,谢谢~