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