Skip to content

Commit 8093f98

Browse files
thierryskodaSpaceK33z
authored andcommitted
Fix for when the root element is null but we still have a nested scheme with that element (#9)
1 parent 34f1087 commit 8093f98

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/parseFormToMutation.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ test('parseFormToMutation - basic', () => {
1616
});
1717
});
1818

19+
test('parseFormToMutation - Nested Scheme with null root', () => {
20+
const values = {
21+
name: 'Summer season',
22+
organization: null
23+
};
24+
const scheme = {
25+
organization: {
26+
__format: create,
27+
address: create
28+
}
29+
};
30+
const formatted = parseFormToMutation(values, scheme);
31+
32+
expect(formatted).toEqual({
33+
name: 'Summer season',
34+
organization: null
35+
});
36+
});
37+
1938
test('parseFormToMutation - advanced', () => {
2039
const values = {
2140
categories: [

src/parseFormToMutation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ export function parseFormToMutation(values: object, scheme: Scheme): object {
4040
currentValue.forEach(value =>
4141
traverseScheme(value, action as Scheme, key, _values)
4242
);
43-
} else {
43+
} else if (currentValue) {
4444
applyParentAction(currentValue, action as Scheme, key, _values);
4545
traverseScheme(currentValue, action as Scheme, key, _values);
4646
}
47-
} else {
47+
} else if (_values) {
4848
_values[key] = (action as ActionFn)(currentValue);
4949
}
5050
});

0 commit comments

Comments
 (0)