0

I need to check if the method is returning an instance of a class, but I'm kinda lost here. I'm getting a ReferenceError when I run the tests.

Mapper.spec.js:

import { SetConfigurationRequestModel } from '../../usecases/Models/SetConfigurationRequestModel'
import { ISetConfigurationRequest } from '../requests/ISetConfigurationRequest'
import { Mapper } from './Mapper'

describe('Helpers/Mappers', () => {
  describe('cfgRequest2RequestModel', () => {
    test('should exist', () => {
      const sut = new Mapper()
      expect(sut.cfgRequest2RequestModel).toBeTruthy()
    })
    test('should be a method', () => {
      const sut = new Mapper()
      expect(typeof sut.cfgRequest2RequestModel).toBe('function')
    })
    test('should return a RequestModel', () => {
      const sut = new Mapper()
      const fakeRequest = makeFakeRequest()
      const requestModel = sut.cfgRequest2RequestModel(fakeRequest)
      expect(requestModel).toBeInstanceOf(SetConfigurationRequestModel)
    })
  })
})

Mapper.js:

import { SetConfigurationRequestModel } from '../../usecases/Models/SetConfigurationRequestModel'
import { ISetConfigurationRequest } from '../requests/ISetConfigurationRequest'

export class Mapper {
  cfgRequest2RequestModel (request: ISetConfigurationRequest): object {
    const request2 = new SetConfigurationRequestModel()
    return request2
  }
}


jest output:

FAIL  src/delivery/helpers/mappers.spec.ts
  ● Helpers/Mappers › cfgRequest2RequestModel › should return a RequestModel

    ReferenceError: SetConfigurationRequestModel is not defined

      4 | export class Mapper {
      5 |   cfgRequest2RequestModel (request: ISetConfigurationRequest): object {
    > 6 |     const request2 = new SetConfigurationRequestModel()
        |                      ^
      7 |     return request2
      8 |   }
      9 | }

      at Mapper.cfgRequest2RequestModel (src/delivery/helpers/Mapper.ts:6:22)
      at Object.<anonymous> (src/delivery/helpers/mappers.spec.ts:42:32)```
2
  • This is possible if import statement is missing or there's a typo in SetConfigurationRequestModel, i.e. there's no variable with this name in module scope. I'm unaware of conditions under which there would be this error with the exact code you posted; Commented Feb 13, 2021 at 7:14
  • @EstusFlask thanks so much, I just realized it was a jest cache problem. Commented Feb 15, 2021 at 14:24

1 Answer 1

1

The problem is not code related.

Just in case somebody goes through the same, add --no-cache options to jest command.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.