Skip to content

Commit

Permalink
[test-suite] Fix ImagePicker's camera tests (#8587)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsapeta committed Jun 1, 2020
1 parent 82ea7c3 commit 3f2aeba
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions apps/test-suite/tests/ImagePicker.js
@@ -1,7 +1,7 @@
import { Platform } from 'react-native';
import Constants from 'expo-constants';
import * as ImagePicker from 'expo-image-picker';
import * as Permissions from 'expo-permissions';
import { Platform } from 'react-native';

import * as TestUtils from '../TestUtils';
import { isDeviceFarm } from '../utils/Environment';
Expand All @@ -24,7 +24,10 @@ export async function test({ it, xit, beforeAll, expect, jasmine, xdescribe, des
expect(shape.height).toBeGreaterThan(0);

expect(typeof shape.type).toBe('string');
expect(shape.type).toBe(type);

if (type) {
expect(shape.type).toBe(type);
}

if (shape.type === 'video') {
expect(typeof shape.duration).toBe('number');
Expand All @@ -49,22 +52,32 @@ export async function test({ it, xit, beforeAll, expect, jasmine, xdescribe, des
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout * 10;
});

if (Constants.isDevice) {
it('launches the camera', async () => {
const { cancelled } = await ImagePicker.launchCameraAsync();
expect(cancelled).toBe(true);
});
} else {
it('natively prevents the camera from launching on a simulator', async () => {
let err;
try {
await ImagePicker.launchCameraAsync();
} catch ({ code }) {
err = code;
}
expect(err).toBe('CAMERA_MISSING');
});
}
describe('launchCameraAsync', () => {
if (Constants.isDevice) {
it('launches the camera', async () => {
alert('Please take a picture for this test to pass.');
const image = await ImagePicker.launchCameraAsync();
expect(image.cancelled).toBe(false);
testMediaObjectShape(image);
});

it('cancels the camera', async () => {
alert('Please cancel the camera for this test to pass.');
const image = await ImagePicker.launchCameraAsync();
expect(image.cancelled).toBe(true);
});
} else {
it('natively prevents the camera from launching on a simulator', async () => {
let err;
try {
await ImagePicker.launchCameraAsync();
} catch ({ code }) {
err = code;
}
expect(err).toBe('CAMERA_MISSING');
});
}
});

describe('launchImageLibraryAsync', async () => {
it('mediaType: image', async () => {
Expand Down

0 comments on commit 3f2aeba

Please sign in to comment.