Jest expect의 method

roglog·2021년 4월 7일
0

Expect


  • Value를 테스트하고 싶을 때 사용하는 함수

Expect Method


  1. toHaveBeenCalledTimes(expected: number)

    • mock funtion이 몇 번 불렸는지 확인
    • Ex)
      expect(coffeeRepositroy.create).toHaveBeenCalledTimes(1)

  2. toHaveBeenCalledWith()

    • mock funtion가 호출될 때 어떤 인수와 호출되는지 확인

    • Ex)

      expect(coffeeRepositroy.create).toHaveBeenCalledWith(createAccountArgs)
      
      expect(coffeeRepositroy.create).toHaveBeenCalledWith(
          expect.any(String),
          expect.any(String)
      )



  3. toHaveBeenCalled()

    • mock funtion가 호출이 되었는지 확인
    • Ex)
      expect(coffeeRepositroy.create).toHaveBeenCalled()

  4. toMathObject()

    • Javascript 개체가 개체의 속성 하위 집합과 일치하는지 확인하는데 사용
    • Ex)
      expect(result).toMatchObject({ ok: false, error: 'Already Done', });

  5. toBeDefined()

    • 변수가 정의 되었는지 확인
    • Ex)
      expect(service).toBeDefined();

  6. toEqual()

    • 두 object이 같은지 확인
    • Ex)
      expect(result).toEqual({ ok: false, error: 'Already Done', });

profile
Full Stack Developer 📚

0개의 댓글