我正在为一个公共方法编写单元测试,而这个方法又调用了用typescript(Node JS)编写的类的私有方法.
示例代码
class A {
constructor() {
}
public method1() {
if(this.method2()) {
// Do something
} else {
// Do something else
}
}
private method2() {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
现在测试method1()我需要stub方法2()这是一个私有方法.
在这里我正在尝试:
sinon.stub(A.prototype, "method2");
Run Code Online (Sandbox Code Playgroud)
Typescript抛出错误:
Argument of type '"method2"' is not assignable to parameter of type '"method1"'
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.谢谢
我下载了 [react-native-redux-typescript-boilerplate]:https : //reactnativeseed.com/。该项目在 android 模拟器中顺利运行。但是,存在大量 tslint 错误,尤其是在 JSX 语法(即 .tsx 文件)中。一个主要的是https://reactnativeseed.com/
我使用 webstrom 作为我的代码编辑器,我交叉检查了 webstrom 和项目使用的打字稿版本。有相同的。
这些是版本: 1. Typescript - 2.6.2 2. react-native - 0.59.6 3. react - 16.2.0 4. react-redux - 5.0.6 5. @types/react - "^16.8.14" 6.@types/react-native - "^0.47.7"
还有什么我需要检查的吗?
我也安装了 ["tslint-fix": "^0.1.3"]: https://www.npmjs.com/package/tslint-fix
例如:index.tsx
import * as React from "react";
import { Item, Input, Icon, Form, Toast } from "native-base";
import { Field, reduxForm } from "redux-form";
import Login from "../../stories/screens/Login";
const required …Run Code Online (Sandbox Code Playgroud)