Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit ef5a310

Browse files
committed
Improve and fix issues with placeholder tests
1 parent f7140f4 commit ef5a310

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
...tsjPreset.transform,
88
'\\.js$': '<rootDir>/node_modules/react-native/jest/preprocessor.js',
99
},
10+
snapshotSerializers: ['enzyme-to-json/serializer'],
1011
setupFiles: ['<rootDir>/tests/config.tsx'],
1112
globals: {
1213
'ts-jest': {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"dv-scripts": "^1.4.2",
7979
"enzyme": "^3.11.0",
8080
"enzyme-adapter-react-16": "^1.15.4",
81+
"enzyme-to-json": "^3.5.0",
8182
"eslint-config-dv-scripts": "^1.1.1",
8283
"jest": "^26.4.2",
8384
"metro-react-native-babel-preset": "^0.63.0",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`CacheableImage renders correctly with placeholder option set 1`] = `
4+
<Text>
5+
Default Placeholder
6+
</Text>
7+
`;
8+
9+
exports[`CacheableImage renders correctly with placeholder prop set 1`] = `
10+
<Text>
11+
Placeholder
12+
</Text>
13+
`;

tests/imageCacheHoc.test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('CacheableImage', function () {
2929
uri:
3030
'file:///base/file/path/react-native-image-cache-hoc/d3b74e9fa8248a5805e2dcf17a8577acd28c089b.png',
3131
})
32+
expect(wrapper.prop('style')).toStrictEqual(styles.image)
3233
done()
3334
})
3435
})
@@ -48,7 +49,7 @@ describe('CacheableImage', function () {
4849
},
4950
})
5051

51-
const propPlaceholder = <Text>Default Placeholder</Text>
52+
const propPlaceholder = <Text>Placeholder</Text>
5253

5354
const wrapper = shallow(
5455
<CacheableImage
@@ -58,7 +59,8 @@ describe('CacheableImage', function () {
5859
/>,
5960
{ disableLifecycleMethods: true },
6061
)
61-
expect(wrapper.prop('style')).toBe(propPlaceholder.props.style)
62+
63+
expect(wrapper).toMatchSnapshot()
6264
})
6365

6466
it('renders correctly with placeholder option set', () => {
@@ -84,6 +86,7 @@ describe('CacheableImage', function () {
8486
<CacheableImage style={styles.image} source={mockData.mockCacheableImageProps.source} />,
8587
{ disableLifecycleMethods: true },
8688
)
87-
expect(wrapper.prop('style')).toBe(optionPlaceholder.props.style)
89+
90+
expect(wrapper).toMatchSnapshot()
8891
})
8992
})

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4666,6 +4666,14 @@ enzyme-shallow-equal@^1.0.1, enzyme-shallow-equal@^1.0.4:
46664666
has "^1.0.3"
46674667
object-is "^1.1.2"
46684668

4669+
enzyme-to-json@^3.5.0:
4670+
version "3.5.0"
4671+
resolved "https://registry.yarnpkg.com/enzyme-to-json/-/enzyme-to-json-3.5.0.tgz#3d536f1e8fb50d972360014fe2bd64e6a672f7dd"
4672+
integrity sha512-clusXRsiaQhG7+wtyc4t7MU8N3zCOgf4eY9+CeSenYzKlFST4lxerfOvnWd4SNaToKhkuba+w6m242YpQOS7eA==
4673+
dependencies:
4674+
lodash "^4.17.15"
4675+
react-is "^16.12.0"
4676+
46694677
enzyme@^3.11.0:
46704678
version "3.11.0"
46714679
resolved "https://registry.yarnpkg.com/enzyme/-/enzyme-3.11.0.tgz#71d680c580fe9349f6f5ac6c775bc3e6b7a79c28"

0 commit comments

Comments
 (0)