Skip to content

Commit

Permalink
chore: add missing test when failing to enhance schema (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Aug 26, 2020
1 parent 9fcd0ae commit a2ec2c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/manifest/__tests__/__mocks__/json-schema-traverse.ts
@@ -0,0 +1,4 @@
import traverse from 'json-schema-traverse';

// note: it's similar as `jest.spyOn`, but as workaround for default exports
export default jest.fn(traverse);
12 changes: 10 additions & 2 deletions src/manifest/__tests__/schema.test.ts
@@ -1,7 +1,11 @@
import * as xdl from '@expo/xdl/build/project/ExpSchema';
import traverse, { TraverseCallback } from 'json-schema-traverse';
import * as schema from '../schema';
import * as tools from '../../../test/tools';

// note: this is the same value as `traverse`, but typed as mock
const mockedTraverse = (traverse as unknown) as jest.Mock<[object, TraverseCallback]>;

describe('getSchema', () => {
it('fetches schema by expo sdk version', async () => {
const xdlSchema = tools.getFixtureFile('schema-xdl-39.0.0.json');
Expand All @@ -15,13 +19,17 @@ describe('getSchema', () => {

describe('createFromXdl', () => {
const xdlSchema = tools.getFixtureFile('schema-xdl-39.0.0.json');
// const simpleSchema = tools.getFixtureFile('schema-plugin-39.0.0.json');
const simpleSchema = tools.getFixtureFile('schema-plugin-39.0.0.json');
const enhancedSchema = tools.getFixtureFile('schema-enhanced-39.0.0.json');

it('creates enhanced plugin schema from xdl', () => {
const createdSchema = schema.createFromXdl('39.0.0', xdlSchema);
expect(createdSchema).toStrictEqual(expect.objectContaining(enhancedSchema));
});

// todo: add test to validate it falls back to original schema
it('uses simple plugin schema when failing to enhance', () => {
mockedTraverse.mockImplementationOnce(() => { throw new Error('Failed traversing schema'); });
const createdSchema = schema.createFromXdl('39.0.0', xdlSchema);
expect(createdSchema).toStrictEqual(expect.objectContaining(simpleSchema));
});
});

0 comments on commit a2ec2c4

Please sign in to comment.