Skip to content

Commit cb3a5cc

Browse files
Naturalclarfacebook-github-bot
authored andcommitted
Add unit test for common parsers method (#34915)
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
1 parent 3ab7ef2 commit cb3a5cc

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
* @oncall react_native
10+
*/
11+
12+
'use-strict';
13+
14+
const {wrapNullable, unwrapNullable} = require('../parsers-commons.js');
15+
16+
describe('wrapNullable', () => {
17+
describe('when nullable is true', () => {
18+
it('returns nullable type annotation', () => {
19+
const result = wrapNullable(true, {
20+
type: 'BooleanTypeAnnotation',
21+
});
22+
const expected = {
23+
type: 'NullableTypeAnnotation',
24+
typeAnnotation: {
25+
type: 'BooleanTypeAnnotation',
26+
},
27+
};
28+
29+
expect(result).toEqual(expected);
30+
});
31+
});
32+
describe('when nullable is false', () => {
33+
it('returns non nullable type annotation', () => {
34+
const result = wrapNullable(false, {
35+
type: 'BooleanTypeAnnotation',
36+
});
37+
const expected = {
38+
type: 'BooleanTypeAnnotation',
39+
};
40+
41+
expect(result).toEqual(expected);
42+
});
43+
});
44+
});
45+
46+
describe('unwrapNullable', () => {
47+
describe('when type annotation is nullable', () => {
48+
it('returns original type annotation', () => {
49+
const result = unwrapNullable({
50+
type: 'NullableTypeAnnotation',
51+
typeAnnotation: {
52+
type: 'BooleanTypeAnnotation',
53+
},
54+
});
55+
const expected = [
56+
{
57+
type: 'BooleanTypeAnnotation',
58+
},
59+
true,
60+
];
61+
62+
expect(result).toEqual(expected);
63+
});
64+
});
65+
describe('when type annotation is not nullable', () => {
66+
it('returns original type annotation', () => {
67+
const result = unwrapNullable({
68+
type: 'BooleanTypeAnnotation',
69+
});
70+
const expected = [
71+
{
72+
type: 'BooleanTypeAnnotation',
73+
},
74+
false,
75+
];
76+
77+
expect(result).toEqual(expected);
78+
});
79+
});
80+
});

0 commit comments

Comments
 (0)