• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

mongoose 6.0.2 버전 오류

21.08.29 14:59 작성 조회수 197

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.

답변 1

답변을 작성해보세요.

0

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

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