inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

getProducts 통합 테스트 작성

mongoose 6.0.2 버전 오류

330

사리곰탕

작성한 질문수 4

0

안녕하세요

강의가 너무 좋아서 한번더 퀵하게 복습 중인데, 그 사이에 mongoose의 메이저버전이 6으로 올라갔습니다.

getProducts 통합 테스트할때, 전체 테스트(npm test)를 하면 오류가 안나지만, jest extension을 이용해서 아래 테스트만 진행하면 오류가 나네요.

it('GET /products', async () => {
  const res = await request(app).get('/products');
  expect(res.statusCode).toBe(200);
  expect(Array.isArray(res.body)).toBeTruthy();
  expect(res.body[0].name).toBeDefined();
  expect(res.body[0].description).toBeDefined();
});

검색해서 좀 알아봐도 뚜렷한 답이 안나와서 혹시 아시는 내용인지 문의 드립니다.

참고로 결과 공유 드립니다

➜  tdd2 node '/Users/lyunhokim/dev/tdd2/node_modules/.bin/jest' '/Users/lyunhokim/dev/tdd2/test/integration/products.int.test.js' -t 'GET /products'
  console.log
    Server is running...

      at Server.<anonymous> (server.js:23:11)

  console.log
    connected

      at server.js:11:11

 FAIL  test/integration/products.int.test.js (5.734 s)
  ✕ GET /products (5007 ms)
  ○ skipped POST /products
  ○ skipped should return 500 on POST /products

  ● GET /products

    MongoInvalidArgumentError: Method "collection.find()" accepts at most two arguments

      at Collection.find (node_modules/mongodb/src/collection.ts:733:13)
      at NativeCollection.<computed> [as find] (node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:191:33)
      at NativeCollection.Object.<anonymous>.Collection.doQueue (node_modules/mongoose/lib/collection.js:135:23)
      at node_modules/mongoose/lib/collection.js:82:24

  ● GET /products

    thrown: "Exceeded timeout of 5000 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

      22 | });
      23 |
    > 24 | it('GET /products', async () => {
         | ^
      25 |   const res = await request(app).get('/products');
      26 |   expect(res.statusCode).toBe(200);
      27 |   expect(Array.isArray(res.body)).toBeTruthy();

      at Object.<anonymous> (test/integration/products.int.test.js:24:1)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 2 skipped, 3 total
Snapshots:   0 total
Time:        5.778 s
Ran all test suites matching /\/Users\/lyunhokim\/dev\/tdd2\/test\/integration\/products.int.test.js/i with tests matching "GET /products".
Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

mongoose express tdd supertest nodejs mongodb jest

답변 1

0

John Ahn

안녕하세요 !  저도 몰랐던 거였는데 알려주셔서 한번 찾아보니깐 
find대신에 findOne을 사용하면 된다고 하네요 ~! 
근데 모든 상품을 찾을때는 find이 필요한데 아직 커뮤니티에는 
버전을 낮춰서 하는것 말고는 정확한 답이 돌고있지는 않은것 같습니다 ~!

안정화 될때 까지는 5버전을 사용하셔도 될것 같습니다 ~! 
https://stackoverflow.com/questions/68926879/cursor-toarray-is-not-a-functioncollection-find-accepts-at-most-two-argumen


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

3040

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