@nyby/detox-component-testing 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/mount.ts CHANGED
@@ -15,25 +15,26 @@ let mountCounter = 0;
15
15
  let appLaunched = false;
16
16
 
17
17
  export function spy(name: string): SpyMarker {
18
- return { [SPY_MARKER]: true, name };
18
+ return {[SPY_MARKER]: true, name};
19
19
  }
20
20
 
21
21
  type MountProps = Record<string, string | number | boolean | SpyMarker>;
22
22
 
23
23
  export async function assertNoRenderError(): Promise<void> {
24
24
  try {
25
- await waitFor(element(by.id('detox-render-error'))).toExist().withTimeout(500);
25
+ await waitFor(element(by.id('detox-render-error')))
26
+ .toExist()
27
+ .withTimeout(500);
26
28
  } catch {
27
29
  return; // Element not found — no render error, all good
28
30
  }
29
31
  // Element exists — read the error message and throw
30
- const attrs = await element(by.id('detox-render-error-message')).getAttributes() as any;
32
+ const attrs = (await element(by.id('detox-render-error-message')).getAttributes()) as any;
31
33
  const message = attrs.text || attrs.label || 'Unknown render error';
32
34
  throw new Error(`Component render error: ${message}`);
33
35
  }
34
36
 
35
37
  export async function mount(componentName: string, props?: MountProps): Promise<void> {
36
-
37
38
  const payload = {
38
39
  id: String(++mountCounter),
39
40
  name: componentName,
@@ -51,33 +52,23 @@ export async function mount(componentName: string, props?: MountProps): Promise<
51
52
  });
52
53
  }
53
54
 
54
- if (!appLaunched) {
55
- const launchArgs: Record<string, any> = { detoxComponentName: componentName };
56
- Object.entries(payload.props).forEach(([key, value]) => {
57
- launchArgs[`detoxProp_${key}`] = value;
58
- });
59
- payload.spies.forEach(name => {
60
- launchArgs[`detoxSpy_${name}`] = true;
61
- });
62
- await device.launchApp({ newInstance: true, launchArgs });
63
- appLaunched = true;
64
- // Harness sets id '0' for the initial launch-args mount
65
- try {
66
- await waitFor(element(by.id('detox-mount-id'))).toHaveText('0').withTimeout(5000);
67
- } catch (e) {
68
- await assertNoRenderError(); // Throws with the actual error if one exists
69
- throw e; // Re-throw original timeout if no render error found
70
- }
71
- await assertNoRenderError();
72
- return;
73
- }
74
-
75
- await element(by.id('detox-harness-control')).replaceText(JSON.stringify(payload));
55
+ const launchArgs: Record<string, any> = {detoxComponentName: componentName};
56
+ Object.entries(payload.props).forEach(([key, value]) => {
57
+ launchArgs[`detoxProp_${key}`] = value;
58
+ });
59
+ payload.spies.forEach((name) => {
60
+ launchArgs[`detoxSpy_${name}`] = true;
61
+ });
62
+ await device.launchApp({newInstance: true, launchArgs});
63
+ appLaunched = true;
64
+ // Harness sets id '0' for the initial launch-args mount
76
65
  try {
77
- await waitFor(element(by.id('detox-mount-id'))).toHaveText(payload.id).withTimeout(5000);
66
+ await waitFor(element(by.id('detox-mount-id')))
67
+ .toHaveText('0')
68
+ .withTimeout(5000);
78
69
  } catch (e) {
79
- await assertNoRenderError();
80
- throw e;
70
+ await assertNoRenderError(); // Throws with the actual error if one exists
71
+ throw e; // Re-throw original timeout if no render error found
81
72
  }
82
73
  await assertNoRenderError();
83
74
  }
package/src/test.ts CHANGED
@@ -1 +1,2 @@
1
- export { mount, spy, expectSpy, assertNoRenderError, SpyMarker, SpyExpectation } from './mount';
1
+ export {mount, spy, expectSpy} from './mount';
2
+ export {debug} from './debug';