-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathhelpers.js
48 lines (41 loc) · 1.08 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { mount } from 'enzyme';
import pDefer from 'p-defer';
import createRender from '../src/createRender';
import resolver from '../src/resolver';
import { getFarceResult } from '../src/server';
export class InstrumentedResolver {
constructor() {
// This should be a rejected promise to prevent awaiting on done before
// trying to resolve, but Node doesn't like naked unresolved promises.
this.done = new Promise(() => {});
}
// eslint-disable-next-line require-await
async *resolveElements(match) {
const deferred = pDefer();
this.done = deferred.promise;
try {
yield* resolver.resolveElements(match);
} finally {
deferred.resolve();
}
}
}
export async function mountFarceResult({
url = '/',
render = createRender({}),
...options
}) {
const { element } = await getFarceResult({ ...options, url, render });
return mount(element);
}
export function mountWithRouter(element, options = {}) {
return mountFarceResult({
...options,
routeConfig: [
{
path: '*',
render: () => element,
},
],
});
}