Jest反应原生,期望常数是[功能BezierEasing]

时间:2018-05-07 12:12:04

标签: reactjs react-native testing jestjs

我已经在反应原生中保持这个常数,只是设置了某些bezier缓和

const easeInQuad = Easing.bezier(0.55, 0.085, 0.68, 0.53);

和相关的玩笑测试

test("Animation/easeInQuad should return correct value", () => {
  expect(easeInQuad).toBe("[Function BezierEasing]");
});

目前输出以下内容

  

动画/ easeInQuad应该返回正确的值

expect(received).toBe(expected) // Object.is equality

Expected value to be:
  "[Function BezierEasing]"
Received:
  [Function BezierEasing]

Difference:

  Comparing two different types of values. Expected string but received function.

我需要传递给expect以匹配输出的内容?

1 个答案:

答案 0 :(得分:1)

您可以使用Function.name检查名称,例如

expect(easeInQuad.name).toBe("BezierEasing");

可能还值得检查它是否是第一个功能:

expect(easeInQuad).toBeInstanceOf(Function);