xref: /expo/apps/test-suite/tests/Contacts.web.js (revision 19cbf4dc)
1import * as Contacts from 'expo-contacts';
2import { Platform, UnavailabilityError } from 'expo-modules-core';
3
4export const name = 'Contacts';
5
6const unavailableMessage = `is unavailable on ${Platform.OS}`;
7
8/* AFAIK there is no native API for using Contacts on the web platform. */
9
10export async function test({ describe, it, expect }) {
11  async function executeFailingMethod(method) {
12    try {
13      await method();
14      expect(true).toBe(false);
15    } catch (error) {
16      expect(error instanceof UnavailabilityError).toBeTruthy();
17    }
18  }
19
20  describe('addContactAsync()', () => {
21    it(unavailableMessage, () => executeFailingMethod(Contacts.addContactAsync));
22  });
23  describe('writeContactToFileAsync()', () => {
24    it(unavailableMessage, () => executeFailingMethod(Contacts.writeContactToFileAsync));
25  });
26  describe('removeContactAsync()', () => {
27    it(unavailableMessage, () => executeFailingMethod(Contacts.removeContactAsync));
28  });
29  describe('getContactsAsync()', () => {
30    it(unavailableMessage, () => executeFailingMethod(Contacts.getContactsAsync));
31  });
32  describe('getContactByIdAsync()', () => {
33    it(unavailableMessage, () => executeFailingMethod(Contacts.getContactByIdAsync));
34  });
35  describe('createGroupAsync()', () => {
36    it(unavailableMessage, () => executeFailingMethod(Contacts.createGroupAsync));
37  });
38  describe('getGroupsAsync()', () => {
39    it(unavailableMessage, () => executeFailingMethod(Contacts.getGroupsAsync));
40  });
41  describe('removeGroupAsync()', () => {
42    it(unavailableMessage, () => executeFailingMethod(Contacts.removeGroupAsync));
43  });
44  describe('getDefaultContainerIdAsync()', () => {
45    it(unavailableMessage, () => executeFailingMethod(Contacts.getDefaultContainerIdAsync));
46  });
47}
48