xref: /expo/apps/test-suite/TestUtils.js (revision 19cbf4dc)
1'use strict';
2
3import { UnavailabilityError } from 'expo-modules-core';
4
5import ExponentTest from './ExponentTest';
6
7export async function acceptPermissionsAndRunCommandAsync(fn) {
8  if (!ExponentTest) {
9    return await fn();
10  }
11
12  const results = await Promise.all([
13    ExponentTest.action({
14      selectorType: 'text',
15      selectorValue: 'Allow',
16      actionType: 'click',
17      delay: 1000,
18      timeout: 100,
19    }),
20    fn(),
21  ]);
22
23  return results[1];
24}
25
26export async function shouldSkipTestsRequiringPermissionsAsync() {
27  if (!ExponentTest || !ExponentTest.shouldSkipTestsRequiringPermissionsAsync) {
28    return false;
29  }
30  return ExponentTest.shouldSkipTestsRequiringPermissionsAsync();
31}
32
33export async function expectMethodToBeUnavailableAsync(expect, method) {
34  const error = await expectMethodToThrowAsync(method);
35  expect(error instanceof UnavailabilityError).toBeTruthy();
36}
37
38export async function expectMethodToThrowAsync(method) {
39  try {
40    await method();
41  } catch (error) {
42    return error;
43  }
44}
45