Skip to content

How to mock @Injectable service in supertested controller? #1879

Answered by Romakita
tkroll asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @tkroll

It's because, you return a plain object javascript and not a class. So the DI doesn't resolve the correct symbol and it explain why you have this message because it's similar to not have theses compilation options.

I suggest you to not use jest.mock.

Here is the solution:

import { PlatformTest } from '@tsed/common'
import SuperTest from 'supertest'
import { Server } from '../../Server'
import { Chapter } from '../../entity/Chapter'

const entity = new Chapter()
Object.assign(entity,  {
  id: 2,
  bookId: 4,
  timestamp: 1650996201,
  name: 'First Day At Work',
})

describe('ChapterController', () => {

  let request: SuperTest.SuperTest<SuperTest.Test>

  beforeAll(PlatformTest

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tkroll
Comment options

Answer selected by tkroll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants