title: How to resolve the type error issue in nestjs unit test?
body: <p>I'm trying to create a jest test for the below method. And I got errors for two scenarios.</p>
  <p>So basically in checkKioskUserPhone method,</p>
  <ol>
  <li><p>Find the user by the phone number( commonService.findKioskUserByPhone)</p>
  </li>
  <li><p>In findKioskUserByPhone method, we are gonna find the user by the phone number and send error messages if it's unregistered or already registered.</p>
  </li>
  <li><p>And then return user.</p>
  </li>
  <li><p>(back to checkKioskUserPhone) if the user doesn't have auth code and pin number we are gonna send him/her auth code and return jwt, and etc.</p>
  </li>
  </ol>
  <pre><code>    async checkKioskUserPhone(kioskLoginDto: KioskLoginDto): Promise&lt;ResponseDto&lt;UserAuthDto&gt;&gt; {
          const user = await this.commonService.findKioskUserByPhone(kioskLoginDto);
  
          const isConfirmedAuthCode = user.authCode === 'OK' ? true : false;
          const isSetPin = user.pin ? true : false;
  
          if (!isConfirmedAuthCode &amp;&amp; !isSetPin) {
              await this.userService.authenticatePhone(user.id, Builder(AuthorizePhoneDto).phone(user.phone).build());
          }
  
          const jwtInfo = await this.createToken(this.removeCredentialField(user));
  
          return Builder&lt;ResponseDto&lt;UserAuthDto&gt;&gt;(ResponseDto)
              .result(Builder(UserAuthDto).isConfirmedAuthCode(isConfirmedAuthCode).isSetPin(isSetPin).jwtInfo(jwtInfo).build())
              .build();
      }
  
  </code></pre>
  <pre><code>
      async findKioskUserByPhone(kioskLoginDto: KioskLoginDto): Promise&lt;User&gt; {
          const user = await this.userService.findOne({ where: { phone: kioskLoginDto.phone } });
  
          // throw Error message when unregistered phone attempt to login
          if (!user) {
              throw new NotFoundException('User not found');
          }
          // throw Error message when registered phone by whatsapp attempt to login
          if (user.provider !== Provider.KIOSK) {
              throw new ConflictException('You are already joined by Whatsapp.');
          }
  
          return user;
      }
  
  </code></pre>
  <p>Jest code</p>
  <pre><code>        it('when unregistered phone attempt to login', async () =&gt; {
              const phone = '2212223333';
              const kioskLoginDto = Builder(KioskLoginDto).phone(phone).build();
  
              service.commonService.findKioskUserByPhone = jest.fn().mockResolvedValue(null);
  
              try {
                  await service.checkKioskUserPhone(kioskLoginDto);
                  expect('here').not.toBe('here');
              } catch (error) {
                  expect(error).toBeInstanceOf(NotFoundException);
                  expect(error.message).toContain('User not found');
              }
          });
  
          it('When registered phone by app attempt to login', async () =&gt; {
              const phone = '2212223333';
              const kioskLoginDto = Builder(KioskLoginDto).phone(phone).build();
              const user = Builder(User).phone(phone).provider(Provider.WHATSAPP).build();
  
              service.commonService.findKioskUserByPhone = jest.fn().mockResolvedValue(user);
  
              try {
                  await service.checkKioskUserPhone(kioskLoginDto);
                  expect('here').not.toBe('here');
              } catch (error) {
                  expect(error).toBeInstanceOf(ConflictException);
                  expect(error.message).toContain('You are already joined by Whatsapp.');
              }
          });
  
  </code></pre>
  <p>Jest Error screenshot</p>
  <p><a href="https://i.stack.imgur.com/UihSo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UihSo.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/ji9Nb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ji9Nb.png" alt="enter image description here" /></a></p>