1
jest로 단위 테스트를 작성하고 제 3 자 라이브러리에서 생성자를 호출하는 함수를 테스트해야합니다 (테스트의 목적은 호출이 이루어 졌는지 확인하는 것입니다). 좋은 인수모조와 제 3 자 라이브러리 생성자 모의
제 3 patry 라이브러리
내가 생성자의 내부에서 온 jest.spyOn(Popper.prototype, 'constructor').mockImplementation(() => {})
있지만 던지고 실수를 한 Popper.js
다음은 나의 테스트 코드입니다.
import Popper from 'popper.js';
it('should call Popper constructor with correct argument',() => {
// Arrange
jest.mockImplementation(Popper.prototype, 'constructor',() => {});
const refElem = document.createElement('div');
const popElem = document.createElement('div');
const placement = 'top';
const container = document.createElement('div');
// Act
popup.create(refElem, popElem, placement, container);
// Assert
expect(Popper.prototype.constructor).toHaveBeenCalled();
});
했나 시험에 행운이 있습니까? 나는 올바른지 (의심 스럽지만) 그것이 작동하는지 여부와 상관없이 단지 두 개의 생성자를'jest.fn()'으로 조롱했다. – MattyK14
@ MattyK14이 질문의 주요 문제점은 제 생성자 중 하나가 아니라 3 부 라이브러리 중 하나였습니다. 어쨌든 작동하는 경우 자유롭게 youor 솔루션을 게시하고 광산을 살펴보십시오. – CharybdeBE