jest_spyOn

악음·2021년 12월 1일
0

jest

목록 보기
3/5
post-thumbnail

spyOn

가짜 함수를 만들지 않고 실질적인 함수를 사용해야할 때가 있다
이때 이함수의 호출 횟수나 어떻게 호출되었는지 알고 싶을때 필요하다

	const caculator={
      add:(a:number,b:number)=>a+b
    }
    test("스파이 on!",()=>{
      const spyFn=jest.spyOn(caculator,"add")
      const result =caculator.add(2,4);
      expect(spyFn).tobeCalledTimes(1)
      expect(spyFn).toHaveBeenCalledWith(2,4)
      expect(result).toBe(6)
    })
profile
RN/react.js개발자이며 배운것들을 제가 보기위해서 정리하기 때문에 비속어 오타가 있을수있습니다.

0개의 댓글