Jest - Support Immutable Objects for ListViewDataSource mock

Summary:
Currently the jest mock for `ListViewDataSource` has a property called `items` which returns the number of items of the data source. Example from a snapshot:

    ListViewDataSource {
      "items": 6,
    }

If the datablob includes immutable Maps like:

    const dataBlob = {
      'alpha': immutable.Map({ name: 'Alpha' }),
      'beta': immutable.Map({ name: 'Beta' }),
    };

then the result is:

    ListViewDataSource {
      "items": NaN,
    }

This PR checks if the properties of the `dataBlob` are immutable Maps and then checks whether they are empty.

The result for the above dataBlob would be:

    ListViewDataSource {
      "items": 2,
    }
Closes https://github.com/facebook/react-native/pull/11567

Differential Revision: D4354977

Pulled By: cpojer

fbshipit-source-id: 9f6bd6ea9896eebd9373344a43ffe97deee5015b
This commit is contained in:
Emmanouil Konstantinidis 2016-12-20 16:45:36 -08:00 коммит произвёл Facebook Github Bot
Родитель 977acb9b68
Коммит 797506f09f
1 изменённых файлов: 3 добавлений и 1 удалений

Просмотреть файл

@ -48,7 +48,9 @@ jest
// Ensure this doesn't throw.
try {
Object.keys(dataBlob).forEach(key => {
this.items += dataBlob[key] && dataBlob[key].length;
this.items += object[key] && (
object[key].length || object[key].size || 0
)
});
} catch (e) {
this.items = 'unknown';