I\'ve created a React component that loads an image and determines if the image loaded successfully or not.
import React from \'react\'; import PropTypes fro
You could mock document.createElement:
document.createElement
it('should call any passed in onError after an image load error', () => { const img = {} global.document.createElement = (type) => type === 'img' ? img : null const onError = jest.fn(); mount(); img.onload() expect(onError).toHaveBeenCalled(); });