I'm writing unit tests with jest and I have to test a function that is calling a constructor from a 3rd party library (the goal of the test is to check that the call is made with good arguments
The 3rd patry library is Popper.js
I have made a jest.spyOn(Popper.prototype, 'constructor').mockImplementation( () => {})
but it is throwing error that came from the inside of the constructor (thus it is not the mock function that has been called)
Here is the code of my test
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();
});