Return waitForActions after rendering

This commit is contained in:
Jerko Steiner 2019-09-11 10:13:34 +07:00
parent 055d9588bf
commit fdbe4be75f
2 changed files with 18 additions and 13 deletions

View File

@ -69,8 +69,7 @@ describe('TeamConnector', () => {
} }
it('it fetches user teams on render', async () => { it('it fetches user teams on render', async () => {
const {waitForActions, render} = createTestProvider() const {node, waitForActions} = createTestProvider().render({
const {node} = render({
history, history,
location: {} as any, location: {} as any,
match: {} as any, match: {} as any,
@ -94,8 +93,8 @@ describe('TeamConnector', () => {
userTeams: [], userTeams: [],
} }
teamClientMock.create.mockResolvedValue(newTeam) teamClientMock.create.mockResolvedValue(newTeam)
const {render, store, waitForActions} = createTestProvider() const {render, store} = createTestProvider()
const {node} = render({ const {waitForActions, node} = render({
history, history,
location: {} as any, location: {} as any,
match: {} as any, match: {} as any,
@ -114,8 +113,8 @@ describe('TeamConnector', () => {
it('displays an error', async () => { it('displays an error', async () => {
const error = {error: 'An error'} const error = {error: 'An error'}
teamClientMock.create.mockRejectedValue(new Error('Test Error')) teamClientMock.create.mockRejectedValue(new Error('Test Error'))
const {render, waitForActions} = createTestProvider() const {render} = createTestProvider()
const {node} = render({ const {node, waitForActions} = render({
history, history,
location: {} as any, location: {} as any,
match: {} as any, match: {} as any,

View File

@ -92,11 +92,17 @@ export class TestUtils {
const jsx = createJSX const jsx = createJSX
? createJSX(Component, props) ? createJSX(Component, props)
: <Component {...props} /> : <Component {...props} />
return this.render( const result = this.render(
<Provider store={store}> <Provider store={store}>
{jsx} {jsx}
</Provider>, </Provider>,
) )
return {
...result,
async waitForActions(timeout = 2000) {
await waitMiddleware.waitForRecorded(recorder)
},
}
} }
const withJSX = (localCreateJSX: CreateJSX) => { const withJSX = (localCreateJSX: CreateJSX) => {
@ -106,14 +112,11 @@ export class TestUtils {
const self: ISelf< const self: ISelf<
Props, typeof store, typeof Component, CreateJSX Props, typeof store, typeof Component, CreateJSX
> = { > = {
render, render,
store, store,
Component, Component,
withJSX, withJSX,
async waitForActions() {
await waitMiddleware.waitForRecorded(recorder, 2000)
},
} }
return self return self
@ -124,10 +127,13 @@ export class TestUtils {
} }
interface ISelf<Props, Store, Component, CreateJSX> { interface ISelf<Props, Store, Component, CreateJSX> {
render: (props: Props) => ReturnType<TestUtils['render']> render: (props: Props) => {
component: React.Component<any>
node: Element
waitForActions(timeout?: number): Promise<void>
}
store: Store store: Store
Component: Component Component: Component
withJSX: (localCreateJSX: CreateJSX) withJSX: (localCreateJSX: CreateJSX)
=> ISelf<Props, Store, Component, CreateJSX> => ISelf<Props, Store, Component, CreateJSX>
waitForActions(): Promise<void>
} }