小编nri*_*ion的帖子

ReferenceError:您试图在Jest环境被拆除后"导入"文件

我有一个组件,它使用Animated来自react native 的组件.我开始编写一个测试用例来模拟onPress一个组件,它调用一个包含Animated.timing在其中的函数setState.

运行jest正常,但测试永远不会停止运行,我之前写过的一个不相关的测试用例现在似乎永远不会通过(之前通过).

运行jest --watch,我收到此错误:

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.

      at Function.bezier (node_modules/react-native/Libraries/Animated/src/Easing.js:113:21)
      at ease (node_modules/react-native/Libraries/Animated/src/Easing.js:34:24)
      at TimingAnimation._easing (node_modules/react-native/Libraries/Animated/src/Easing.js:133:18)
      at TimingAnimation.onUpdate (node_modules/react-native/Libraries/Animated/src/animations/TimingAnimation.js:107:45)

 RUNS  src/__tests__/SlideDownMenu.test.js

/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:114
      return _bezier(x1, y1, x2, y2);
             ^
TypeError: _bezier is not a function
    at Function.bezier (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:224:12)
    at ease (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:94:21)
    at TimingAnimation._easing (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/Easing.js:255:16)
    at TimingAnimation.onUpdate (/home/nrion/Desktop/mobile-ui/PriceInsight_app/node_modules/react-native/Libraries/Animated/src/animations/TimingAnimation.js:138:14)
    at ontimeout (timers.js:386:11)
    at tryOnTimeout (timers.js:250:5)
    at …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs react-native enzyme

14
推荐指数
8
解决办法
4561
查看次数

MacOS:iterm2,zsh 取消过程,control + c 不起作用,但它适用于 control + m 或 control + shift + c

好吧,这很奇怪。我的终端(带有 zsh 的 iterm2)使用control + mcontrol + shift + cnow 而不是仅退出命令control + c

关于为什么会发生这种情况的任何想法?谢谢!

macos zsh iterm2 oh-my-zsh macos-mojave

8
推荐指数
1
解决办法
1047
查看次数

是否可以在所有eslint规则上显示警告而不是错误?

如标题所述,eslint是否有可能在所有规则上显示警告而不是错误?如果该信息相关,我正在使用Standard JS。

谢谢!

reactjs eslint react-native standardjs eslintrc

6
推荐指数
2
解决办法
3157
查看次数

按月份和年份对 MongoDB 中的数据进行排序

伙计们!我的 MongoDB 中有这些数据:

{
    "_id" : ObjectId("5aa35c78e84868839683c4ca"),
    "dateTransacted" : ISODate("2018-03-10T04:18:00.074Z"),
    "taskerFee" : 1500,
    "customerFee" : 4000,
    "transactionFee" : 50,
    "mnmltaskrProfit" : 30
},
{
    "_id" : ObjectId("5aa3ac08e84868839683c4cb"),
    "dateTransacted" : ISODate("2018-03-10T09:57:28.637Z"),
    "taskerFee" : 300,
    "customerFee" : 1500,
    "transactionFee" : 50,
    "mnmltaskrProfit" : 60
}
Run Code Online (Sandbox Code Playgroud)

我想按月和年查询它,以便它返回类似以下内容的内容:

{
  'month': 'September',
  'year': 2018,
  'transactions': [
    {
      "_id" : ObjectId("5aa3ac08e84868839683c4cb"),
      "dateTransacted" : ISODate("2018-03-10T09:57:28.637Z"),
      "taskerFee" : 300,
      "customerFee" : 1500,
      "transactionFee" : 50,
      "mnmltaskrProfit" : 60
    },
    {
      "_id" : ObjectId("5aa3ac08e84868839683c4cb"),
      "dateTransacted" : ISODate("2018-03-10T09:57:28.637Z"),
      "taskerFee" : …
Run Code Online (Sandbox Code Playgroud)

sorting mongodb aggregation-framework

4
推荐指数
1
解决办法
3383
查看次数

在 Bootstrap 4.1 中将 col 文本与背景颜色垂直居中对齐

这是实际工作的代码在中间对齐文本:

<div class="container section-content">
    <div class="row" style="border-radius: 4px; border: solid 1px #979797;">
        <div class="col-md-3 align-self-center" style="background-color: #4a90e2">
            Align
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

但这是输出: 在此处输入图片说明 所需的输出应该用背景颜色填充整个左列。

我如何实现这一目标?

编辑:不是如何使 Bootstrap 列的高度相同? 这是垂直对齐的问题

html css twitter-bootstrap bootstrap-4

3
推荐指数
1
解决办法
1791
查看次数

使用 jest/enzyme 测试调用 setState 的异步 componentDidMount

我的里面有以下代码async componentdidmount

async componentDidMount() {
    try {
        let responseText = await API.Licensing()
        this.setState({ html: responseText })
    } catch (e) {
        this.setState({ html: 'Error Fetching Licensing Info' })
    }
}
Run Code Online (Sandbox Code Playgroud)

我对如何在这里测试 setstate 感到困惑,因为互联网上的大多数示例都使用 Promise then/catch,而这个示例使用 try/catch async/await。

测试会是什么样子?

reactjs jestjs enzyme

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