title: Jest: Cannot spy the property because it is not a function; undefined given instead getting error while executing my test cases
body: <pre><code>           This is my controller class(usercontoller.ts) i am trying to write junit test cases for this class  
  
              import { UpsertUserDto } from '../shared/interfaces/dto/upsert-user.dto';
              import { UserDto } from '../shared/interfaces/dto/user.dto';
              import { UserService } from './user.service';
                  async updateUser(@BodyToClass() user: UpsertUserDto): Promise&lt;UpsertUserDto&gt; {
                      try {
                          if (!user.id) {
                              throw new BadRequestException('User Id is Required');
                          }
                          return await this.userService.updateUser(user);
                      } catch (e) {
                          throw e;
                      }
                  } 
  </code></pre>
  
  <p>This is my TestClass(UserContollerspec.ts)
  while running my test classes getting error " Cannot spy the updateUser property because it is not a function; undefined given instead.
  getting error.
  However, when I use spyOn method, I keep getting TypeError: Cannot read property 'updateuser' of undefined: </p>
  
  <p>*it seems jest.spyOn() not working properly where i am doing mistake.
   could some one please help me.the argument which I am passing ? </p>
  
  <pre><code>    jest.mock('./user.service');
  
          describe('User Controller', () =&gt; {
              let usercontroller: UserController;
              let userservice: UserService;
              // let fireBaseAuthService: FireBaseAuthService;
              beforeEach(async () =&gt; {
                  const module: TestingModule = await Test.createTestingModule({
                      controllers: [UserController],
                      providers: [UserService]
                  }).compile();
  
                  usercontroller = module.get&lt;UserController&gt;(UserController);
  
                  userservice = module.get&lt;UserService&gt;(UserService);
              });
  
              afterEach(() =&gt; {
                  jest.resetAllMocks();
              });
  
           describe('update user', () =&gt; {
               it('should return a user', async () =&gt; {
                 //const result = new  UpsertUserDto();
                 const testuser =  new  UpsertUserDto();
                 const mockDevice = mock &lt;Promise&lt;UpsertUserDto&gt;&gt;();
                 const mockNumberToSatisfyParameters = 0;
                 //const userservice =new UserService();
                 //let userservice: UserService;
                  jest.spyOn(userservice, 'updateUser').mockImplementation(() =&gt; mockDevice);
                expect(await usercontroller.updateUser(testuser)).toBe(mockDevice);
  
            it('should throw internal  error if user not found', async (done) =&gt; {
              const expectedResult = undefined;
               ****jest.spyOn(userservice, 'updateUser').mockResolvedValue(expectedResult);****
               await usercontroller.updateUser(testuser)
                .then(() =&gt; done.fail('Client controller should return NotFoundException error of 404 but did not'))
                .catch((error) =&gt; {
                  expect(error.status).toBe(503);
                  expect(error.message).toMatchObject({error: 'Not Found', statusCode: 503});  done();
              });
          });
          });
          });
  </code></pre>