import React from 'react'; import { render } from '@testing-library/react'; import { EventrixProvider } from '../context'; import Eventrix from '../../Eventrix'; import withEventrix from './withEventrix'; import { EventrixI } from '../../interfaces'; describe('withEventrix', () => { const TestComponent = ({ foo = '', eventrix }: { foo: string; eventrix: EventrixI }) => { eventrix.emit('testEvent'); return
{!!foo &&
{foo}
}
; }; interface Props { foo: string; } const WrappedComponentTest = withEventrix(TestComponent); const TestContainer = ({ eventrix, children }: any) => {children}; it('should run callback when component render', async () => { const mockedCallback = jest.fn(); const eventrixInstance = new Eventrix({}); eventrixInstance.listen('testEvent', mockedCallback); render( , ); expect(mockedCallback).toHaveBeenCalled(); }); });