比方说我有以下打字稿课:
class MyComponent {
private something: number;
constructor () {
this.something = 0
this.incrementSomething()
}
private incrementSomething () : number {
return this.something++
}
}
export default MyComponent
我的目标是使用jest
进行测试,但是我有更多的问题要回答。
jest coverage
的设置,因为它将报告未测试的课程?这是我第一次尝试在private
中使用typescript
方法并对其进行测试,所以请耐心等候:)
答案 0 :(得分:2)
我不认为SO是解决此类问题的理想之地,因为您要问的大部分内容都是基于观点的。但是,您可以断言该对象是any
以便进行一些测试:
class MyComponent {
private something: number;
constructor () {
this.something = 0
this.incrementSomething()
}
private incrementSomething () : number {
return this.something++
}
}
const thingIWantToTest = new MyComponent();
console.log((thingIWantToTest as any).something); // works
console.log(thingIWantToTest.something); // type error