marmelab / FakeRest

Patch fetch/XMLHttpRequest to fake a REST API server in the browser, based on JSON data.
MIT License
439 stars 48 forks source link

Fix Collection.update() may erase values #86

Closed fzaninotto closed 3 weeks ago

fzaninotto commented 3 weeks ago

Problem

Calling Collection.update() with an object containing undefined values erases the existing value.

// will erase the title
collection.updateOne(0, { name: 'FOO', title: undefined });

This does not mimic true REST APIs because, when the change payload is serialized to be passed to the network, undefined values are removed.

The erasure is unexpected.

Solution

Better mimic REST APIs by serializing / unserializing the changes before applying them.

fzaninotto commented 3 weeks ago

This has to be done at the fake server level, not at the collection or database level. FetchMock, MSW and Sinon adapters work properly, the problem only occurs in ra-data-fakerest. That's where the fix should be done.