小编Pol*_*sas的帖子

延迟建议时间 Material-UI Autocomplete 组件

任何人都知道如何在给出建议之前延迟时间?

一旦我写了第一封信,它就给了我建议,我想推迟一下,我通读了文档但找不到它,也许不可能?

reactjs material-ui

7
推荐指数
3
解决办法
5773
查看次数

WithProps vs withHandlers

我一直在寻找反应重构库并试图掌握差异,结果是一样的,试图阅读文档,但更加困惑,为什么有两种方法可以做同样的事情?

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)

reactjs recompose

5
推荐指数
2
解决办法
3536
查看次数

开玩笑测试中的多个方法调用会导致错误的期望

刚刚开始深入测试世界,有一件事让我感到困惑。我有这样的课:

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 被调用了两次。

所以我的问题是,是否有可能以某种方式隔离这些测试?当我运行测试一(调用某个类方法)时,它不应该影响其他测试结果。

谢谢!

javascript unit-testing jestjs

2
推荐指数
1
解决办法
2135
查看次数