小编Ino*_*ani的帖子

出现类型错误:即使在正确设置后,expect(...).toBeInTheDocument 也不是一个函数

我使用 Create React App 并已经在 src/setupTests.js 上声明了这一点:

import '@testing-library/jest-dom';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
Run Code Online (Sandbox Code Playgroud)

但每次我expect(anything).toBeInTheDocument()在测试文件上使用时,运行测试时我都会得到:

TypeError: expect(...).toBeInTheDocument is not a function
Run Code Online (Sandbox Code Playgroud)

为了确保 setupTests.js 实际运行,我尝试在测试文件上使用酶浅层并且它有效。那么 jest-dom 到底存在什么问题以及如何解决呢?

jest-dom

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

找不到模块“babel-eslint”(标准和 babel-eslint 均已在本地安装)

什么版本的标准?

12.0.1

什么操作系统、Node.js 和 npm 版本?

Windows 10、节点 v10.15.1、NPM v.6.8.0

您预计会发生什么?

  • 我在 devDependencies 上(本地)安装了标准版和 babel-eslint。
  • 我跑standard --parser babel-eslint
  • 我得到标准使用 babel-eslint 解析器来识别 babel 代码风格,而不是将其声明为风格错误

究竟发生了什么?

  • 我在 devDependencies 上(本地)安装了标准版和 babel-eslint。

  • 我运行标准 --parser babel-eslint

  • 我收到错误:找不到模块“babel-eslint”

我从以前的问题85 1167中读到,当它们安装在同一层时应该修复。但它不会发生在我身上。

我尝试将以下配置放在 package.json 上:

"standard": {
    "parser": "babel-eslint"
  }
Run Code Online (Sandbox Code Playgroud)

但这并不能解决问题。

standardjs

7
推荐指数
2
解决办法
4万
查看次数

默认导出类的新实例

下面的代码片段每次导入时都会生成新实例吗?

// 1st implementation

class ConnectionManager {
...
}

export default new ConnectionManager();
Run Code Online (Sandbox Code Playgroud)
// 2nd implementation

class ConnectionManager {
...
}

const connectionManager = new ConnectionManager();
export default connectionManager;
Run Code Online (Sandbox Code Playgroud)

如果是,如何在每次导入中获得相同的实例?

javascript es6-modules

5
推荐指数
3
解决办法
4313
查看次数

无法连接到 MongoDB Atlas (queryTxt ETIMEOUT)

我无法通过驱动程序、mongoshell 或 MongoDB 指南针连接到 MongoDB Atlas。获取错误:queryTxt ETIMEOUT

Error:  { Error: queryTxt ETIMEOUT clustermasjeed1-ekpfe.mongodb.net
    at QueryReqWrap.onresolve [as oncomplete] (dns.js:197:19)
  errno: 'ETIMEOUT',
  code: 'ETIMEOUT',
  syscall: 'queryTxt',
  hostname: 'clustermasjeed1-ekpfe.mongodb.net' }
Run Code Online (Sandbox Code Playgroud)

我遵循了 mongodb atlas (mongodb.cloud) 关于如何连接的指南:

const MongoClient = require(‘mongodb’).MongoClient;
const uri = "mongodb+srv://<username>:<password>@clustermasjeed1-ekpfe.mongodb.net/test?retryWrites=true";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
  const collection = client.db("test").collection("devices");
  // perform actions on the collection object
  client.close();
});
Run Code Online (Sandbox Code Playgroud)

用真实字符串值替换用户名和密码。我有强烈的感觉,原因是 +srv 部分。之前使用mlab的时候,连接只有mongodb://(没有+srv)

mongodb express mongodb-atlas

0
推荐指数
2
解决办法
4050
查看次数