Skip to content

Commit 95da6b1

Browse files
committed
Add tests for handling empty objects and undefined entries in dirty fields
1 parent bb5b551 commit 95da6b1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/ra-core/src/form/useFormIsDirty.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,23 @@ describe('useFormIsDirty', () => {
114114
};
115115
expect(checkHasDirtyFields(dirtyFields)).toBe(false);
116116
});
117+
118+
it('should return true when an array contains an empty object (new item)', () => {
119+
const dirtyFields = {
120+
name: false,
121+
age: false,
122+
hobbies: [{}], // empty object should be considered dirty
123+
};
124+
expect(checkHasDirtyFields(dirtyFields)).toBe(true);
125+
});
126+
127+
it('should return true when an array contains undefined entries (new item)', () => {
128+
const dirtyFields = {
129+
name: false,
130+
age: false,
131+
hobbies: [undefined], // undefined should be considered dirty
132+
} as any;
133+
expect(checkHasDirtyFields(dirtyFields)).toBe(true);
134+
});
117135
});
118136
});

0 commit comments

Comments
 (0)