Skip to content

Commit 9f5bf40

Browse files
committed
test(codegen): add a test for computePartialProperties
1 parent f1994ff commit 9f5bf40

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

packages/react-native-codegen/src/parsers/__tests__/parsers-test.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,61 @@ describe('FlowParser', () => {
110110
expect(parser.callExpressionTypeParameters(node)).toBe(null);
111111
});
112112
});
113+
114+
describe('computePartialProperties', () => {
115+
it('returns partial properties', () => {
116+
const properties = [
117+
{
118+
type: 'ObjectTypeProperty',
119+
key: {
120+
type: 'Identifier',
121+
name: 'a',
122+
},
123+
value: {
124+
type: 'StringTypeAnnotation',
125+
range: [],
126+
},
127+
},
128+
{
129+
type: 'ObjectTypeProperty',
130+
key: {
131+
type: 'Identifier',
132+
name: 'b',
133+
},
134+
optional: true,
135+
value: {
136+
type: 'BooleanTypeAnnotation',
137+
range: [],
138+
},
139+
},
140+
];
141+
142+
const expected = [
143+
{
144+
name: 'a',
145+
optional: true,
146+
typeAnnotation: {type: 'StringTypeAnnotation'},
147+
},
148+
{
149+
name: 'b',
150+
optional: true,
151+
typeAnnotation: {type: 'BooleanTypeAnnotation'},
152+
},
153+
];
154+
155+
expect(
156+
parser.computePartialProperties(
157+
properties,
158+
'hasteModuleName',
159+
{},
160+
{},
161+
{},
162+
() => null,
163+
false,
164+
),
165+
).toEqual(expected);
166+
});
167+
});
113168
});
114169

115170
describe('TypeScriptParser', () => {
@@ -202,4 +257,73 @@ describe('TypeScriptParser', () => {
202257
expect(parser.callExpressionTypeParameters(node)).toBe(null);
203258
});
204259
});
260+
261+
describe('computePartialProperties', () => {
262+
it('returns partial properties', () => {
263+
const properties = [
264+
{
265+
type: 'TSPropertySignature',
266+
key: {
267+
type: 'Identifier',
268+
name: 'a',
269+
},
270+
typeAnnotation: {
271+
type: 'TSTypeAnnotation',
272+
typeAnnotation: {
273+
type: 'TSTypeLiteral',
274+
key: {
275+
type: 'Identifier',
276+
name: 'a',
277+
},
278+
members: [],
279+
},
280+
},
281+
},
282+
{
283+
type: 'TSPropertySignature',
284+
key: {
285+
type: 'Identifier',
286+
name: 'b',
287+
},
288+
optional: true,
289+
typeAnnotation: {
290+
type: 'TSTypeAnnotation',
291+
typeAnnotation: {
292+
type: 'TSStringKeyword',
293+
key: {
294+
type: 'Identifier',
295+
name: 'b',
296+
},
297+
members: [],
298+
},
299+
},
300+
},
301+
];
302+
303+
const expected = [
304+
{
305+
name: 'a',
306+
optional: true,
307+
typeAnnotation: {properties: [], type: 'ObjectTypeAnnotation'},
308+
},
309+
{
310+
name: 'b',
311+
optional: true,
312+
typeAnnotation: {type: 'StringTypeAnnotation'},
313+
},
314+
];
315+
316+
expect(
317+
parser.computePartialProperties(
318+
properties,
319+
'hasteModuleName',
320+
{},
321+
{},
322+
{},
323+
() => null,
324+
false,
325+
),
326+
).toEqual(expected);
327+
});
328+
});
205329
});

0 commit comments

Comments
 (0)