[fix] Image 'source' prop update when missing in initial render

Close #811
This commit is contained in:
Jakub Rimal
2018-02-12 08:26:28 -08:00
committed by Nicolas Gallagher
parent fb4635e013
commit 748b2d0f3f
2 changed files with 16 additions and 2 deletions
@@ -180,6 +180,20 @@ describe('components/Image', () => {
.attr('src')
).toBe(uriTwo);
});
test('is correctly updated when missing in initial render', () => {
jest.useFakeTimers();
const uri = 'https://testing.com/img.jpg';
const component = mount(<Image />);
component.setProps({ source: { uri } });
jest.runOnlyPendingTimers();
expect(
component
.render()
.find('img')
.attr('src')
).toBe(uri);
});
});
describe('prop "style"', () => {
+2 -2
View File
@@ -168,8 +168,8 @@ class Image extends Component<*, State> {
if (uri !== nextUri) {
ImageUriCache.remove(uri);
const isPreviouslyLoaded = ImageUriCache.has(nextUri);
isPreviouslyLoaded && ImageUriCache.add(uri);
this._updateImageState(getImageState(uri, isPreviouslyLoaded));
isPreviouslyLoaded && ImageUriCache.add(nextUri);
this._updateImageState(getImageState(nextUri, isPreviouslyLoaded));
}
}