inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

따라하며 배우는 TDD 개발 [2023.11 업데이트]

통합테스트 에러 해결 방법

955

u0938223

작성한 질문수 1

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;

// 터미널

supertest express tdd mongodb nodejs mongoose jest

답변 2

0

u0938223

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

일단 주소 남기겠습니다

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

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

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

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


이렇게 나오더라구요.

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

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

이렇게 되던데

대체 뭘까요?

0

John Ahn

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

TypeError: user_model_1.default.create is not a function

0

255

1

에러 처리를 위한 단위테스트 작성

0

345

1

res.status(201) 부분에서 typeerror가 발생합니다

0

388

1

따라하며 배우는 TDD 개발 [2023.11 업데이트] 강의 질문

0

334

1

[MAC] PORT:5000번 관련 에러

0

273

0

테스트를 위한 데이터베이스를 생성해야하나요?

0

402

1

Postman 사용방법에 대해서

0

401

1

jest.fn() 을 할당할때 타입스크립트에서 에러가 발생합니다.

0

445

1

라우터를 돌릴 때

0

354

1

npm run start를 실행할 때 부터가 이상합니다.

1

433

1

node.js에 대한 이상점

0

454

1

nodemocks 오류나니까 뺴고 설치하셔요

1

410

1

Node.js 앱을 테스트하기 위한 Jest 설정 부분..

0

272

0

models 파일만 첫번째 글자를 대문자로 해주는 이유

0

298

1

mongodb project 및 cluster관련

0

329

0

무조건 failure case 로 넘어가시는 분들

2

259

1

올려둔 ES6 Express Jest Boilerplate Template 으로 개발 중이신 분들...

0

237

0

ES6 사용하고 싶은 분들...

1

360

0

Jest did not exit one second after the test run has completed. 이슈

0

3041

3

왜 인자네개 함수 안만들어도 포스트맨에서는 에러메세지가 나오는 것인가요?

0

301

2

통합 테스트에 관한 질문 이 있습니다.

0

243

1

bodyParser 대체에 관한 질문

0

424

2

Cannot log after tests are done. Did you forget to wait for something async in your test?

0

2121

1

안녕하세요. 문의드립니다.

0

203

1