最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

我的测试无法通过JEST,我遇到了一些错误

IT培训 admin 12浏览 0评论

我的测试无法通过JEST,我遇到了一些错误

我将按照一些教程向我展示代码。当我尝试实现它并运行JEST时出现错误,并且测试无法通过]

const mongoose = require('mongoose')
const supertest = require('supertest')
const app = require('../app')

const api = supertest(app)

test('notes are returned as json', async () => {
  await api
    .get('/api/notes')
    .expect(200)
    .expect('Content-Type', /application\/json/)
})

test('there are four notes', async () => {
  const response = await api.get('/api/notes')

  expect(response.body.length).toBe(4)
})

test('the first note is about HTTP methods', async () => {
  const response = await api.get('/api/notes')

  expect(response.body[0].content).toBe('HTML is easy')
})

afterAll(async () => {
  await mongoose.connection.close()
})

我遇到这种错误

也就是那行说“测试运行完成后,Jest没有退出一秒钟。”我已经用该代码在应用程序的根目录中制作了jest.config.js文件,以防止出现这种情况,但是它仍然显示为某种错误。

module.exports = {
    testEnvironment: 'node',
  }

帮帮我

回答如下:

在屏幕上,有关于Jest失败的非常具体的信息。

我的测试无法通过JEST,我遇到了一些错误

我将按照一些教程向我展示代码。当我尝试实现它并运行JEST时出现错误,并且测试无法通过]

const mongoose = require('mongoose')
const supertest = require('supertest')
const app = require('../app')

const api = supertest(app)

test('notes are returned as json', async () => {
  await api
    .get('/api/notes')
    .expect(200)
    .expect('Content-Type', /application\/json/)
})

test('there are four notes', async () => {
  const response = await api.get('/api/notes')

  expect(response.body.length).toBe(4)
})

test('the first note is about HTTP methods', async () => {
  const response = await api.get('/api/notes')

  expect(response.body[0].content).toBe('HTML is easy')
})

afterAll(async () => {
  await mongoose.connection.close()
})

我遇到这种错误

也就是那行说“测试运行完成后,Jest没有退出一秒钟。”我已经用该代码在应用程序的根目录中制作了jest.config.js文件,以防止出现这种情况,但是它仍然显示为某种错误。

module.exports = {
    testEnvironment: 'node',
  }

帮帮我

回答如下:

在屏幕上,有关于Jest失败的非常具体的信息。

发布评论

评论列表 (0)

  1. 暂无评论