1 | import { shallow } from 'enzyme';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export function shallowUntilTarget(componentInstance, TargetComponent, options) {
|
11 | if (options === void 0) { options = {
|
12 | maxTries: 10,
|
13 | shallowOptions: {},
|
14 | }; }
|
15 | var maxTries = options.maxTries, shallowOptions = options.shallowOptions;
|
16 | var root = shallow(componentInstance, shallowOptions);
|
17 | var rootType = root.type();
|
18 | if (typeof rootType === 'string' || rootType.toString().indexOf(TargetComponent) !== -1) {
|
19 |
|
20 |
|
21 |
|
22 | return root;
|
23 | }
|
24 | for (var tries = 1; tries <= maxTries; tries++) {
|
25 |
|
26 |
|
27 | if (rootType.toString().indexOf(TargetComponent) !== -1) {
|
28 |
|
29 | return root.first().shallow(shallowOptions);
|
30 | }
|
31 |
|
32 | root = root.first().shallow(shallowOptions);
|
33 | rootType = root.type();
|
34 | }
|
35 | throw new Error("Could not find " + TargetComponent + " in React instance: " + componentInstance + ";\n gave up after " + maxTries + " tries");
|
36 | }
|
37 |
|
\ | No newline at end of file |