Skip to content

Commit f3b24dd

Browse files
author
Chris Kosuke Tseng
authored
Merge pull request #100 from Expensify/marcaaron-fixComponentLoadsWhenNoKeysRequiredForInit
Add test and fix enable-payments page issue
2 parents 57ca276 + cf25489 commit f3b24dd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/withOnyx.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export default function (mapOnyxToState) {
4141
this.tempState = {};
4242

4343
this.state = {
44-
loading: true,
44+
// If there are no required keys for init then we can render the wrapped component immediately
45+
loading: requiredKeysForInit.length > 0,
4546
};
4647
}
4748

tests/unit/withOnyxTest.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,25 @@ describe('withOnyx', () => {
156156
});
157157
});
158158

159+
it('should render the WrappedComponent if no keys are required for init', () => {
160+
const INITIAL_VALUE = 'initial_value';
161+
const TestComponentWithOnyx = withOnyx({
162+
text: {
163+
key: 'test',
164+
initWithStoredValues: false,
165+
},
166+
})(ViewWithText);
167+
TestComponentWithOnyx.defaultProps = {
168+
text: INITIAL_VALUE,
169+
};
170+
Onyx.set('test_key', 'test_text');
171+
return waitForPromisesToResolve()
172+
.then(() => {
173+
const {getByTestId} = render(<TestComponentWithOnyx collectionID="1" />);
174+
expect(getByTestId('text-element').props.children).toEqual(INITIAL_VALUE);
175+
});
176+
});
177+
159178
it('should pass a prop from one connected component to another', () => {
160179
const collectionItemID = 1;
161180
const onRender = jest.fn();

0 commit comments

Comments
 (0)