Skip to content

Commit

Permalink
Add unit test for common parsers method (#34915)
Browse files Browse the repository at this point in the history
Summary:
This PR is part of #34872
This PR adds unit test for method that were refactored into parsers-commons.js in codegen in #34898

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - Add unit test for common parsers method

Pull Request resolved: #34915

Test Plan: `yarn jest react-native-codegen`

Reviewed By: cipolleschi

Differential Revision: D40219036

Pulled By: cipolleschi

fbshipit-source-id: 2fb666c016f7822feaf2156d23ce7ffb9572c756
  • Loading branch information
Naturalclar authored and facebook-github-bot committed Oct 10, 2022
1 parent 3ab7ef2 commit cb3a5cc
Showing 1 changed file with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/

'use-strict';

const {wrapNullable, unwrapNullable} = require('../parsers-commons.js');

describe('wrapNullable', () => {
describe('when nullable is true', () => {
it('returns nullable type annotation', () => {
const result = wrapNullable(true, {
type: 'BooleanTypeAnnotation',
});
const expected = {
type: 'NullableTypeAnnotation',
typeAnnotation: {
type: 'BooleanTypeAnnotation',
},
};

expect(result).toEqual(expected);
});
});
describe('when nullable is false', () => {
it('returns non nullable type annotation', () => {
const result = wrapNullable(false, {
type: 'BooleanTypeAnnotation',
});
const expected = {
type: 'BooleanTypeAnnotation',
};

expect(result).toEqual(expected);
});
});
});

describe('unwrapNullable', () => {
describe('when type annotation is nullable', () => {
it('returns original type annotation', () => {
const result = unwrapNullable({
type: 'NullableTypeAnnotation',
typeAnnotation: {
type: 'BooleanTypeAnnotation',
},
});
const expected = [
{
type: 'BooleanTypeAnnotation',
},
true,
];

expect(result).toEqual(expected);
});
});
describe('when type annotation is not nullable', () => {
it('returns original type annotation', () => {
const result = unwrapNullable({
type: 'BooleanTypeAnnotation',
});
const expected = [
{
type: 'BooleanTypeAnnotation',
},
false,
];

expect(result).toEqual(expected);
});
});
});

0 comments on commit cb3a5cc

Please sign in to comment.