• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

통합테스트 에러 해결 방법

21.05.12 17:05 작성 조회수 678

0

현재 Create 통합 테스트 작성의 

통합 테스트 작성하기 까지 다 들은 상태인데요,

분명 똑같이 따라했는데

A worker process has failed to exit gracefully and has been force exited. This is likely caused by tests leaking due to improper teardown. Try running with --detectOpenHandles to find leaks.

위의 에러 메세지가 뜨더라고요..

구글링해서

package.json에

"test": "jest --runInBand --detectOpenHandles"

이렇게 해줬는데

이렇게 하니까 이번엔

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

이 에러가 뜹니다;;

계속 구글링해보고 있긴한데 해결이 안되서

질문 남깁니다.

// test/integration/products.int.test.js

const request = require('supertest');
const app = require('../../server');

const newProduct = require('../data/new-product.json');

it("POST /api/products", async () => {
const response = await request(app)
.post("api/products")
.send(newProduct);
expect(response.statusCode).toBe(201)
expect(response.body.name).toBe(newProduct.name)
expect(response.body.description).toBe(newProduct.description)
})

// server.js

const express = require('express');

// Constants
const PORT = 5000;

// App
const app = express();
const productRoutes = require('./routes')
const mongoose = require('mongoose');

const user = 'databaseuser';
const password = 'young4262';
const db = 'ttd';

mongoose.connect(`mongodb+srv://${user}:${password}@cluster0.1weod.mongodb.net/${db}?retryWrites=true&w=majority`,
{
useNewUrlParser: true, // 경고 문구 뜨지 않게
useUnifiedTopology: true
})
.then(() => console.log('Mongodb Connected...'))
.catch(err => console.log(err));

app.use(express.json());

app.use('/api/products', productRoutes)

app.get('/', (req, res) => {
res.send('Hello')
})

app.listen(PORT, () => console.log(`Running on port ${PORT}`));

module.exports = app;

// 터미널

답변 2

·

답변을 작성해보세요.

0

u0938223님의 프로필

u0938223

질문자

2021.05.15

제가 이것만 따로 파질 않았는데 괜찮을까요..?

일단 주소 남기겠습니다

https://github.com/u00938/TIL/tree/main/TDD/practice

근데 일단 해결되긴 했습니다. 그대로 쭉 그냥 완강까지 달리고 나서,

jest 옵션에 달았던것들을 빼고

"test": "jest" 상태로 테스트 하니


이렇게 나오더라구요.

저 주황색 글이 신경쓰여 하라는대로 --detectOpenHandles 옵션을 붙여서

"test": "jest --detectOpenHandles" 로 테스트하면

이렇게 되던데

대체 뭘까요?

0

안녕하세요 혹시  깃헙 페이지를 올려주실수있나요?  제가 직접해보는게 더 에러 잡기가 쉬울것같아서요 ~ ~