From 63cfbd37776b1c4a56ad337c8ae9bc1da5defa7e Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 5 May 2023 07:37:39 -0600 Subject: [PATCH 1/6] Pass props to selector --- lib/Onyx.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/Onyx.js b/lib/Onyx.js index 43427aefa..efdeb7be9 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -48,12 +48,13 @@ const deferredInitTask = createDeferredTask(); * Uses a selector string or function to return a simplified version of sourceData * @param {Mixed} sourceData * @param {String|Function} selector + * @param {Object} [withOnyxInstanceProps] * If it's a string, the selector is passed to lodashGet on the sourceData * If it's a function, it is passed the sourceData and it should return the simplified data * @returns {Mixed} */ -const getSubsetOfData = (sourceData, selector) => (_.isFunction(selector) - ? selector(sourceData) +const getSubsetOfData = (sourceData, selector, withOnyxInstanceProps) => (_.isFunction(selector) + ? selector(sourceData, withOnyxInstanceProps) : lodashGet(sourceData, selector)); /** @@ -62,11 +63,12 @@ const getSubsetOfData = (sourceData, selector) => (_.isFunction(selector) * The resulting collection will only contain items that are returned by the selector. * @param {Object} collection * @param {String|Function} selector (see method docs for getSubsetOfData() for full details) + * @param {Object} [withOnyxInstanceProps] * @returns {Object} */ -const reduceCollectionWithSelector = (collection, selector) => _.reduce(collection, (finalCollection, item, key) => { +const reduceCollectionWithSelector = (collection, selector, withOnyxInstanceProps) => _.reduce(collection, (finalCollection, item, key) => { // eslint-disable-next-line no-param-reassign - finalCollection[key] = getSubsetOfData(item, selector); + finalCollection[key] = getSubsetOfData(item, selector, withOnyxInstanceProps); return finalCollection; }, {}); @@ -362,8 +364,8 @@ function keysChanged(collectionKey, partialCollection) { // returned by the selector. if (subscriber.selector) { subscriber.withOnyxInstance.setState((prevState) => { - const previousData = reduceCollectionWithSelector(prevState[subscriber.statePropertyName], subscriber.selector); - const newData = reduceCollectionWithSelector(cachedCollection, subscriber.selector); + const previousData = reduceCollectionWithSelector(prevState[subscriber.statePropertyName], subscriber.selector, subscriber.withOnyxInstance.props); + const newData = reduceCollectionWithSelector(cachedCollection, subscriber.selector, subscriber.withOnyxInstance.props); if (!deepEqual(previousData, newData)) { return { @@ -406,7 +408,7 @@ function keysChanged(collectionKey, partialCollection) { if (subscriber.selector) { subscriber.withOnyxInstance.setState((prevState) => { const prevData = prevState[subscriber.statePropertyName]; - const newData = getSubsetOfData(cachedCollection[subscriber.key], subscriber.selector); + const newData = getSubsetOfData(cachedCollection[subscriber.key], subscriber.selector, subscriber.withOnyxInstance.props); if (!deepEqual(prevData, newData)) { PerformanceUtils.logSetStateCall(subscriber, prevData, newData, 'keysChanged', collectionKey); return { @@ -488,11 +490,11 @@ function keyChanged(key, data, canUpdateSubscriber) { subscriber.withOnyxInstance.setState((prevState) => { const prevData = prevState[subscriber.statePropertyName]; const newData = { - [key]: getSubsetOfData(data, subscriber.selector), + [key]: getSubsetOfData(data, subscriber.selector, subscriber.withOnyxInstance.props), }; const prevDataWithNewData = { ...prevData, - [key]: getSubsetOfData(data, subscriber.selector), + [key]: getSubsetOfData(data, subscriber.selector, subscriber.withOnyxInstance.props), }; if (!deepEqual(prevData, prevDataWithNewData)) { PerformanceUtils.logSetStateCall(subscriber, prevData, newData, 'keyChanged', key); @@ -523,8 +525,8 @@ function keyChanged(key, data, canUpdateSubscriber) { // returned by the selector and only if the selected data has changed. if (subscriber.selector) { subscriber.withOnyxInstance.setState((prevState) => { - const previousValue = getSubsetOfData(prevState[subscriber.statePropertyName], subscriber.selector); - const newValue = getSubsetOfData(data, subscriber.selector); + const previousValue = getSubsetOfData(prevState[subscriber.statePropertyName], subscriber.selector, subscriber.withOnyxInstance.props); + const newValue = getSubsetOfData(data, subscriber.selector, subscriber.withOnyxInstance.props); if (!deepEqual(previousValue, newValue)) { return { [subscriber.statePropertyName]: newValue, @@ -662,9 +664,10 @@ function getCollectionDataAndSendAsObject(matchingKeys, mapping) { * component * @param {Boolean} [mapping.waitForCollectionCallback] If set to true, it will return the entire collection to the callback as a single object * @param {String|Function} [mapping.selector] THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data. - * If the selector is a string, the selector is passed to lodashGet on the sourceData. If the selector is a function, the sourceData is passed to the selector and should return the - * simplified data. Using this setting on `withOnyx` can have very positive performance benefits because the component will only re-render when the subset of data changes. - * Otherwise, any change of data on any property would normally cause the component to re-render (and that can be expensive from a performance standpoint). + * If the selector is a string, the selector is passed to lodashGet on the sourceData. If the selector is a function, the sourceData and withOnyx instance props are + * passed to the selector and should return the simplified data. Using this setting on `withOnyx` can have very positive performance benefits because the component + * will only re-render when the subset of data changes. Otherwise, any change of data on any property would normally cause the component to re-render (and that can + * be expensive from a performance standpoint). * @returns {Number} an ID to use when calling disconnect */ function connect(mapping) { From 58bc7cc22947f87f594edfedd8f0fbcccec8b30c Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 5 May 2023 07:44:43 -0600 Subject: [PATCH 2/6] Update a test to check that props were passed to the selector --- tests/unit/subscribeToPropertiesTest.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/subscribeToPropertiesTest.js b/tests/unit/subscribeToPropertiesTest.js index 3dc4c3a51..5b708a84b 100644 --- a/tests/unit/subscribeToPropertiesTest.js +++ b/tests/unit/subscribeToPropertiesTest.js @@ -49,7 +49,7 @@ describe('Only the specific property changes when using withOnyx() and ', () => * @returns {Promise} */ const runAssertionsWithComponent = (TestComponentWithOnyx) => { - let renderedComponent = render(); + let renderedComponent = render(); return waitForPromisesToResolve() // When Onyx is updated with an object that has multiple properties @@ -108,6 +108,10 @@ describe('Only the specific property changes when using withOnyx() and ', () => }, })(ViewWithObject); return runAssertionsWithComponent(TestComponentWithOnyx) + .then(() => { + // Check to make sure that the instance props were passed to the selector + expect(mockedSelector).toHaveBeenNthCalledWith(3, {a: 'one', b: 'two'}, {forwardedRef: null, testProp: 'test'}); + }) .then(() => { // This checks to make sure a bug doesn't occur where the entire state object was being passed to // the selector From cd31f6c495e681d68c0665d53875b2672addbab6 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 5 May 2023 07:47:33 -0600 Subject: [PATCH 3/6] Update docs --- API.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/API.md b/API.md index 233c2ebc0..6f81a4527 100644 --- a/API.md +++ b/API.md @@ -5,10 +5,10 @@ ## Functions
-
getSubsetOfData(sourceData, selector)Mixed
+
getSubsetOfData(sourceData, selector, [withOnyxInstanceProps])Mixed

Uses a selector string or function to return a simplified version of sourceData

-
reduceCollectionWithSelector(collection, selector)Object
+
reduceCollectionWithSelector(collection, selector, [withOnyxInstanceProps])Object

Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}}) and runs it through a reducer function to return a subset of the data according to a selector. The resulting collection will only contain items that are returned by the selector.

@@ -77,7 +77,7 @@ value will be saved to storage after the default value.

-## getSubsetOfData(sourceData, selector) ⇒ Mixed +## getSubsetOfData(sourceData, selector, [withOnyxInstanceProps]) ⇒ Mixed Uses a selector string or function to return a simplified version of sourceData **Kind**: global function @@ -85,11 +85,12 @@ Uses a selector string or function to return a simplified version of sourceData | Param | Type | Description | | --- | --- | --- | | sourceData | Mixed | | -| selector | String \| function | If it's a string, the selector is passed to lodashGet on the sourceData If it's a function, it is passed the sourceData and it should return the simplified data | +| selector | String \| function | | +| [withOnyxInstanceProps] | Object | If it's a string, the selector is passed to lodashGet on the sourceData If it's a function, it is passed the sourceData and it should return the simplified data | -## reduceCollectionWithSelector(collection, selector) ⇒ Object +## reduceCollectionWithSelector(collection, selector, [withOnyxInstanceProps]) ⇒ Object Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}}) and runs it through a reducer function to return a subset of the data according to a selector. The resulting collection will only contain items that are returned by the selector. @@ -100,6 +101,7 @@ The resulting collection will only contain items that are returned by the select | --- | --- | --- | | collection | Object | | | selector | String \| function | (see method docs for getSubsetOfData() for full details) | +| [withOnyxInstanceProps] | Object | | @@ -128,7 +130,7 @@ Subscribes a react component's state directly to a store key | [mapping.callback] | function | a method that will be called with changed data This is used by any non-React code to connect to Onyx | | [mapping.initWithStoredValues] | Boolean | If set to false, then no data will be prefilled into the component | | [mapping.waitForCollectionCallback] | Boolean | If set to true, it will return the entire collection to the callback as a single object | -| [mapping.selector] | String \| function | THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data. If the selector is a string, the selector is passed to lodashGet on the sourceData. If the selector is a function, the sourceData is passed to the selector and should return the simplified data. Using this setting on `withOnyx` can have very positive performance benefits because the component will only re-render when the subset of data changes. Otherwise, any change of data on any property would normally cause the component to re-render (and that can be expensive from a performance standpoint). | +| [mapping.selector] | String \| function | THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data. If the selector is a string, the selector is passed to lodashGet on the sourceData. If the selector is a function, the sourceData and withOnyx instance props are passed to the selector and should return the simplified data. Using this setting on `withOnyx` can have very positive performance benefits because the component will only re-render when the subset of data changes. Otherwise, any change of data on any property would normally cause the component to re-render (and that can be expensive from a performance standpoint). | **Example** ```js From e07c2d3ba4f346da145a6c8b713f1ff11223b79a Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 5 May 2023 11:42:01 -0600 Subject: [PATCH 4/6] Pass state instead of props --- API.md | 14 +++++------ lib/Onyx.js | 32 ++++++++++++------------- tests/unit/subscribeToPropertiesTest.js | 14 +++++++---- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/API.md b/API.md index 6f81a4527..82b7777f4 100644 --- a/API.md +++ b/API.md @@ -5,10 +5,10 @@ ## Functions
-
getSubsetOfData(sourceData, selector, [withOnyxInstanceProps])Mixed
+
getSubsetOfData(sourceData, selector, [withOnyxInstanceState])Mixed

Uses a selector string or function to return a simplified version of sourceData

-
reduceCollectionWithSelector(collection, selector, [withOnyxInstanceProps])Object
+
reduceCollectionWithSelector(collection, selector, [withOnyxInstanceState])Object

Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}}) and runs it through a reducer function to return a subset of the data according to a selector. The resulting collection will only contain items that are returned by the selector.

@@ -77,7 +77,7 @@ value will be saved to storage after the default value.

-## getSubsetOfData(sourceData, selector, [withOnyxInstanceProps]) ⇒ Mixed +## getSubsetOfData(sourceData, selector, [withOnyxInstanceState]) ⇒ Mixed Uses a selector string or function to return a simplified version of sourceData **Kind**: global function @@ -86,11 +86,11 @@ Uses a selector string or function to return a simplified version of sourceData | --- | --- | --- | | sourceData | Mixed | | | selector | String \| function | | -| [withOnyxInstanceProps] | Object | If it's a string, the selector is passed to lodashGet on the sourceData If it's a function, it is passed the sourceData and it should return the simplified data | +| [withOnyxInstanceState] | Object | If it's a string, the selector is passed to lodashGet on the sourceData If it's a function, it is passed the sourceData and it should return the simplified data | -## reduceCollectionWithSelector(collection, selector, [withOnyxInstanceProps]) ⇒ Object +## reduceCollectionWithSelector(collection, selector, [withOnyxInstanceState]) ⇒ Object Takes a collection of items (eg. {testKey_1:{a:'a'}, testKey_2:{b:'b'}}) and runs it through a reducer function to return a subset of the data according to a selector. The resulting collection will only contain items that are returned by the selector. @@ -101,7 +101,7 @@ The resulting collection will only contain items that are returned by the select | --- | --- | --- | | collection | Object | | | selector | String \| function | (see method docs for getSubsetOfData() for full details) | -| [withOnyxInstanceProps] | Object | | +| [withOnyxInstanceState] | Object | | @@ -130,7 +130,7 @@ Subscribes a react component's state directly to a store key | [mapping.callback] | function | a method that will be called with changed data This is used by any non-React code to connect to Onyx | | [mapping.initWithStoredValues] | Boolean | If set to false, then no data will be prefilled into the component | | [mapping.waitForCollectionCallback] | Boolean | If set to true, it will return the entire collection to the callback as a single object | -| [mapping.selector] | String \| function | THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data. If the selector is a string, the selector is passed to lodashGet on the sourceData. If the selector is a function, the sourceData and withOnyx instance props are passed to the selector and should return the simplified data. Using this setting on `withOnyx` can have very positive performance benefits because the component will only re-render when the subset of data changes. Otherwise, any change of data on any property would normally cause the component to re-render (and that can be expensive from a performance standpoint). | +| [mapping.selector] | String \| function | THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data. If the selector is a string, the selector is passed to lodashGet on the sourceData. If the selector is a function, the sourceData and withOnyx state are passed to the selector and should return the simplified data. Using this setting on `withOnyx` can have very positive performance benefits because the component will only re-render when the subset of data changes. Otherwise, any change of data on any property would normally cause the component to re-render (and that can be expensive from a performance standpoint). | **Example** ```js diff --git a/lib/Onyx.js b/lib/Onyx.js index efdeb7be9..8244dacbf 100644 --- a/lib/Onyx.js +++ b/lib/Onyx.js @@ -48,13 +48,13 @@ const deferredInitTask = createDeferredTask(); * Uses a selector string or function to return a simplified version of sourceData * @param {Mixed} sourceData * @param {String|Function} selector - * @param {Object} [withOnyxInstanceProps] + * @param {Object} [withOnyxInstanceState] * If it's a string, the selector is passed to lodashGet on the sourceData * If it's a function, it is passed the sourceData and it should return the simplified data * @returns {Mixed} */ -const getSubsetOfData = (sourceData, selector, withOnyxInstanceProps) => (_.isFunction(selector) - ? selector(sourceData, withOnyxInstanceProps) +const getSubsetOfData = (sourceData, selector, withOnyxInstanceState) => (_.isFunction(selector) + ? selector(sourceData, withOnyxInstanceState) : lodashGet(sourceData, selector)); /** @@ -63,12 +63,12 @@ const getSubsetOfData = (sourceData, selector, withOnyxInstanceProps) => (_.isFu * The resulting collection will only contain items that are returned by the selector. * @param {Object} collection * @param {String|Function} selector (see method docs for getSubsetOfData() for full details) - * @param {Object} [withOnyxInstanceProps] + * @param {Object} [withOnyxInstanceState] * @returns {Object} */ -const reduceCollectionWithSelector = (collection, selector, withOnyxInstanceProps) => _.reduce(collection, (finalCollection, item, key) => { +const reduceCollectionWithSelector = (collection, selector, withOnyxInstanceState) => _.reduce(collection, (finalCollection, item, key) => { // eslint-disable-next-line no-param-reassign - finalCollection[key] = getSubsetOfData(item, selector, withOnyxInstanceProps); + finalCollection[key] = getSubsetOfData(item, selector, withOnyxInstanceState); return finalCollection; }, {}); @@ -364,8 +364,8 @@ function keysChanged(collectionKey, partialCollection) { // returned by the selector. if (subscriber.selector) { subscriber.withOnyxInstance.setState((prevState) => { - const previousData = reduceCollectionWithSelector(prevState[subscriber.statePropertyName], subscriber.selector, subscriber.withOnyxInstance.props); - const newData = reduceCollectionWithSelector(cachedCollection, subscriber.selector, subscriber.withOnyxInstance.props); + const previousData = reduceCollectionWithSelector(prevState[subscriber.statePropertyName], subscriber.selector, subscriber.withOnyxInstance.state); + const newData = reduceCollectionWithSelector(cachedCollection, subscriber.selector, subscriber.withOnyxInstance.state); if (!deepEqual(previousData, newData)) { return { @@ -408,7 +408,7 @@ function keysChanged(collectionKey, partialCollection) { if (subscriber.selector) { subscriber.withOnyxInstance.setState((prevState) => { const prevData = prevState[subscriber.statePropertyName]; - const newData = getSubsetOfData(cachedCollection[subscriber.key], subscriber.selector, subscriber.withOnyxInstance.props); + const newData = getSubsetOfData(cachedCollection[subscriber.key], subscriber.selector, subscriber.withOnyxInstance.state); if (!deepEqual(prevData, newData)) { PerformanceUtils.logSetStateCall(subscriber, prevData, newData, 'keysChanged', collectionKey); return { @@ -490,11 +490,11 @@ function keyChanged(key, data, canUpdateSubscriber) { subscriber.withOnyxInstance.setState((prevState) => { const prevData = prevState[subscriber.statePropertyName]; const newData = { - [key]: getSubsetOfData(data, subscriber.selector, subscriber.withOnyxInstance.props), + [key]: getSubsetOfData(data, subscriber.selector, subscriber.withOnyxInstance.state), }; const prevDataWithNewData = { ...prevData, - [key]: getSubsetOfData(data, subscriber.selector, subscriber.withOnyxInstance.props), + [key]: getSubsetOfData(data, subscriber.selector, subscriber.withOnyxInstance.state), }; if (!deepEqual(prevData, prevDataWithNewData)) { PerformanceUtils.logSetStateCall(subscriber, prevData, newData, 'keyChanged', key); @@ -525,8 +525,8 @@ function keyChanged(key, data, canUpdateSubscriber) { // returned by the selector and only if the selected data has changed. if (subscriber.selector) { subscriber.withOnyxInstance.setState((prevState) => { - const previousValue = getSubsetOfData(prevState[subscriber.statePropertyName], subscriber.selector, subscriber.withOnyxInstance.props); - const newValue = getSubsetOfData(data, subscriber.selector, subscriber.withOnyxInstance.props); + const previousValue = getSubsetOfData(prevState[subscriber.statePropertyName], subscriber.selector, subscriber.withOnyxInstance.state); + const newValue = getSubsetOfData(data, subscriber.selector, subscriber.withOnyxInstance.state); if (!deepEqual(previousValue, newValue)) { return { [subscriber.statePropertyName]: newValue, @@ -584,9 +584,9 @@ function sendDataToConnection(mapping, val, matchedKey) { // returned by the selector. if (mapping.selector) { if (isCollectionKey(mapping.key)) { - newData = reduceCollectionWithSelector(val, mapping.selector); + newData = reduceCollectionWithSelector(val, mapping.selector, mapping.withOnyxInstance.state); } else { - newData = getSubsetOfData(val, mapping.selector); + newData = getSubsetOfData(val, mapping.selector, mapping.withOnyxInstance.state); } } @@ -664,7 +664,7 @@ function getCollectionDataAndSendAsObject(matchingKeys, mapping) { * component * @param {Boolean} [mapping.waitForCollectionCallback] If set to true, it will return the entire collection to the callback as a single object * @param {String|Function} [mapping.selector] THIS PARAM IS ONLY USED WITH withOnyx(). If included, this will be used to subscribe to a subset of an Onyx key's data. - * If the selector is a string, the selector is passed to lodashGet on the sourceData. If the selector is a function, the sourceData and withOnyx instance props are + * If the selector is a string, the selector is passed to lodashGet on the sourceData. If the selector is a function, the sourceData and withOnyx state are * passed to the selector and should return the simplified data. Using this setting on `withOnyx` can have very positive performance benefits because the component * will only re-render when the subset of data changes. Otherwise, any change of data on any property would normally cause the component to re-render (and that can * be expensive from a performance standpoint). diff --git a/tests/unit/subscribeToPropertiesTest.js b/tests/unit/subscribeToPropertiesTest.js index 5b708a84b..91eeab5da 100644 --- a/tests/unit/subscribeToPropertiesTest.js +++ b/tests/unit/subscribeToPropertiesTest.js @@ -49,7 +49,7 @@ describe('Only the specific property changes when using withOnyx() and ', () => * @returns {Promise} */ const runAssertionsWithComponent = (TestComponentWithOnyx) => { - let renderedComponent = render(); + let renderedComponent = render(); return waitForPromisesToResolve() // When Onyx is updated with an object that has multiple properties @@ -110,7 +110,7 @@ describe('Only the specific property changes when using withOnyx() and ', () => return runAssertionsWithComponent(TestComponentWithOnyx) .then(() => { // Check to make sure that the instance props were passed to the selector - expect(mockedSelector).toHaveBeenNthCalledWith(3, {a: 'one', b: 'two'}, {forwardedRef: null, testProp: 'test'}); + // expect(mockedSelector).toHaveBeenCalledWith({a: 'one', b: 'two'}, {loading: false, propertyA: 'one'}); }) .then(() => { // This checks to make sure a bug doesn't occur where the entire state object was being passed to @@ -185,13 +185,19 @@ describe('Only the specific property changes when using withOnyx() and ', () => }); it('connecting to a collection with a selector function', () => { + const mockedSelector = jest.fn(obj => obj && obj.a); const TestComponentWithOnyx = withOnyx({ collectionWithPropertyA: { key: ONYX_KEYS.COLLECTION.TEST_KEY, - selector: obj => obj && obj.a, + selector: mockedSelector, }, })(ViewWithObject); - return runAllAssertionsForCollection(TestComponentWithOnyx); + return runAllAssertionsForCollection(TestComponentWithOnyx) + .then(() => { + console.log(mockedSelector.mock.calls) + // Check to make sure that the selector was called with the props that are passed to the rendered component + expect(mockedSelector).toHaveBeenNthCalledWith(5, {a: 'two', b: 'two'}, {loading: false, collectionWithPropertyA: {test_1: 'one', test_2: undefined}}); + }); }); /** From e2b8da1a6a9fed6c0b27dc5443e67b9132fa7658 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 5 May 2023 11:44:47 -0600 Subject: [PATCH 5/6] Remove unnecessary code --- tests/unit/subscribeToPropertiesTest.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/unit/subscribeToPropertiesTest.js b/tests/unit/subscribeToPropertiesTest.js index 91eeab5da..b77e7abf3 100644 --- a/tests/unit/subscribeToPropertiesTest.js +++ b/tests/unit/subscribeToPropertiesTest.js @@ -108,10 +108,6 @@ describe('Only the specific property changes when using withOnyx() and ', () => }, })(ViewWithObject); return runAssertionsWithComponent(TestComponentWithOnyx) - .then(() => { - // Check to make sure that the instance props were passed to the selector - // expect(mockedSelector).toHaveBeenCalledWith({a: 'one', b: 'two'}, {loading: false, propertyA: 'one'}); - }) .then(() => { // This checks to make sure a bug doesn't occur where the entire state object was being passed to // the selector From 0abf1cc119f9e8a47a48e501a9a8ac92c3be69fb Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Fri, 5 May 2023 14:12:27 -0600 Subject: [PATCH 6/6] Fix style --- tests/unit/subscribeToPropertiesTest.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/unit/subscribeToPropertiesTest.js b/tests/unit/subscribeToPropertiesTest.js index b77e7abf3..3af41a544 100644 --- a/tests/unit/subscribeToPropertiesTest.js +++ b/tests/unit/subscribeToPropertiesTest.js @@ -189,11 +189,10 @@ describe('Only the specific property changes when using withOnyx() and ', () => }, })(ViewWithObject); return runAllAssertionsForCollection(TestComponentWithOnyx) - .then(() => { - console.log(mockedSelector.mock.calls) - // Check to make sure that the selector was called with the props that are passed to the rendered component - expect(mockedSelector).toHaveBeenNthCalledWith(5, {a: 'two', b: 'two'}, {loading: false, collectionWithPropertyA: {test_1: 'one', test_2: undefined}}); - }); + .then(() => { + // Check to make sure that the selector was called with the props that are passed to the rendered component + expect(mockedSelector).toHaveBeenNthCalledWith(5, {a: 'two', b: 'two'}, {loading: false, collectionWithPropertyA: {test_1: 'one', test_2: undefined}}); + }); }); /**