我有一个场景,我的承诺拒绝了一个错误对象。
throw new Error(`${ISSUE}`);
问题包含一个常见的字符串is causing this issue。这方面的一些例子可以是:
ISSUE = 'Node is causing this issue', OR
ISSUE = 'Jest is causing this issue'
为了使用Jest测试这个场景,我使用toHaveProperty(),如下所示:
expect(function()).rejects.toHaveProperty('message',/is cau
我将TypeScript中的mongodb库用于一些函数(例如lambda函数,但这不重要)。
进口品看起来是这样的:
import { ObjectId, Db, InsertOneResult } from "mongodb";
当我导入Jest中的函数并执行它时,我总是会得到错误:
Module '"../../node_modules/mongodb/mongodb.ts34"' declares 'ObjectId' locally, but it is not exported.
我认为我的玩笑逻辑有问题,但我不确定是
我使用jest测试我的react,我使用expect(...).toBeCalledWith(...);测试一个函数是否有特定的参数被调用,并且它在值类型中工作得很好。
问题是,我想测试一个函数,它将对象作为参数,所以当您调用expect(myFunc).toBeCalledWith(object);时,测试总是失败的,因为当然,两个对象之间的比较不具有相同的引用。
那么我该如何解决这个问题呢?
我正在尝试测试的示例代码是
it('the function should be called with the correct object', () => {
api
我已经阅读了Jest documentation,但我没有找到任何解释我的目标的示例代码。这是我当前的代码; 这些任务,我用来在validateRegular()的return上用.toMatchObject method匹配预期的对象。 // This is the function for validate the object.
const { validateRegular } = require('../src/options/validate')
// This is just a function that return an object if valida
import Store from 'electron-store';
class Test {
private storeInstance: any;
public initialise() {
if(!Test.storeInstance) {
Test.storeInstance = new Store({name: 'test', key:123}); // returns Default
}
}
public getInstance() {
return Test.storeIn
我设置了一个jest starter,以便对使用jest-mongodb的内存中的mongodb运行集成测试 "jest": {
"preset": "@shelf/jest-mongodb", 但是,运行npx jest得到的结果是 > jest-starter@1.0.0 test my/path/jest-starter
> jest
Determining test suites to run...(node:10769) ExperimentalWarning: Conditional exports is
我希望将函数返回值的数据结构与更大的结构(即返回的结构“验证”)与更完整的哈希进行匹配。我有一个使用toHaveProperty的工作测试,但我不希望在针对这个特定问题的测试中定义对象结构。
我真正想要的是让我测试包含在更大的散列中的结构(而不是值),并找出不调用函数两次的方法:
// ** this would fail if a property value is different **
test('thing returns something matching the structure within types', () => {
expect(thi
在这个问题上有很多线程,没有一个解决方案对我有用。我正在使用NestJS、TypeORM和Cosmos DB Mongo。
我正在我的机器上运行NestJS服务,点击Azure中的数据库。我可以很好地从集合中读取,但是每当我尝试编写时,我都会得到以下错误:
MongoError: Retryable writes are not supported. Please disable retryable writes by specifying "retrywrites=false" in the connection string or an equivalent driver
我试图将jest-mongodb与ts-jest一起使用,它在本地机器上运行得很好,但当我开始在码头或CircleCI之类的孤立地方运行它时,它拒绝工作,并不停地说:
Error: Jest: Got error running globalSetup - /app/node_modules/@shelf/****-mongodb/setup.js, reason: Instance Exited before being ready and without throwing an error!
据我所知,这就是这些jest库在process.env中不能正常工作的问题。
或者如果我像这样直接
我正在用jest在express的基本mongodb设置上运行测试。按照中的说明操作。当我运行五月package.json脚本:"test": "jest"时,我得到以下错误:
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (node_modules/@shelf/jest-mongodb/environment.js:20:49)
上面提到的environment.js中的行是:
modul
我正在跟踪关于的文档。当我试图运行一个测试时,我会得到以下错误:
Error: Jest: Got error running globalSetup - /home/.../node_modules/@shelf/jest-mongodb/setup.js, reason: Instance Exited before being ready and without throwing an error!
这既发生在我使用类型记录时,也发生在我使用javascript创建一个简单的应用程序时:
package.json:
{
"name": "mongojest
Jest的一个主要特性是它的高级expect匹配器,它允许非常细粒度的JS对象匹配。
// We expect an object (dict) which strictly equals the following
expect(myObject).toStrictEqual({
foo: "Hello",
// Any valid number will match for the bar property
bar: expect.any(Number),
});
expect(myObject).toStrictEqual({
// Any string
我正在学习如何使用这个NodeJS和MongoDB来创建RestAPI,从他们提供的回购中可以得到很多更新,我进一步修改了它,用Jest和SuperTest完成了Mongo服务器的UnitTesting。
在添加我的回购之前,我对回购所做的主要修改是:
将侦听逻辑移动到start.js,而在package.json中将此作为主文件
start.js
const { app } = require("./index");
// Setup server port
var port = process.env.PORT || 8080;
app.listen(port, fun