import React from 'react'
import { mount } from 'enzyme'
import { createBrowserHistory } from 'history';
import { EventEmitter } from 'events'
import { withSyncHistory } from '../src/utils';
describe('Test Sync History', () => {
test('Sync History Emitter', () => {
const emitter = new EventEmitter();
const history = createBrowserHistory();
// @ts-ignore
const Application = (props) => (
{props.test}
)
const SyncApplication = withSyncHistory(Application, history);
let called = false
const unlisten = history.listen((location) => {
called = true;
expect(location.pathname).toEqual('/test')
})
const wrapper = mount(
)
expect(called).toBe(true)
unlisten();
let received = 0;
emitter.on('test:history-change', (location) => {
received = received + 1;
expect(location.pathname).toEqual('/bar')
});
wrapper.setProps({ path: '/bar' });
expect(received).toEqual(1);
expect(wrapper.containsMatchingElement(1
)).toBe(true)
expect(wrapper.children().exists()).toBe(true);
wrapper.unmount();
history.push('/unmount');
expect(received).toEqual(1);
})
})