From 797506f09f4b7b1b216350d2ce32b21eebccfc85 Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Tue, 20 Dec 2016 16:45:36 -0800 Subject: [PATCH] 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 --- jest/setup.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jest/setup.js b/jest/setup.js index e559702056d..9d28442c25b 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -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';