任何人都知道如何在给出建议之前延迟时间?
一旦我写了第一封信,它就给了我建议,我想推迟一下,我通读了文档但找不到它,也许不可能?
我一直在寻找反应重构库并试图掌握差异,结果是一样的,试图阅读文档,但更加困惑,为什么有两种方法可以做同样的事情?
const enhance = compose(
withState('counter', 'setCounter', 0),
withHandlers({
increment: props => () => props.setCounter(n => n + 1),
decrement: props => () => props.setCounter(n => n - 1)
})
)
const enhance = compose(
withState('counter', 'setCounter', 0),
withProps(({ setCounter }) => ({
increment: () => setCounter(n => n + 1),
decrement: () => setCounter(n => n - 1)
}))
)
Run Code Online (Sandbox Code Playgroud) 刚刚开始深入测试世界,有一件事让我感到困惑。我有这样的课:
class TestClass {
static staticMethod () {
methodOne();
methodTwo();
}
Run Code Online (Sandbox Code Playgroud)
并像这样测试:
test('should call methodOne function', () => {
TestClass.staticMethod();
expect(methodOne).toHaveBeenCalled();
});
test('should call methodTwo function', () => {
Test.staticMethod();
expect(methodTwo).toHaveBeenCalled();
expect(methodTwo).toHaveBeenCalledTimes(1);
});
Run Code Online (Sandbox Code Playgroud)
Jest 抛出一个错误,说 methodTwo 被调用了两次而不是一次。我想,这是因为我正在运行两个测试,两次调用类静态方法(第一次测试中一次,第二次测试中第二次),因此 methodTwo 被调用了两次。
所以我的问题是,是否有可能以某种方式隔离这些测试?当我运行测试一(调用某个类方法)时,它不应该影响其他测试结果。
谢谢!