Skip to content

Commit

Permalink
feat: add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akinncar committed Oct 4, 2021
1 parent 754f34d commit d7dcb04
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"@commitlint/config-conventional": "^11.0.0",
"@react-native-community/eslint-config": "^2.0.0",
"@release-it/conventional-changelog": "^2.0.0",
"@testing-library/react-native": "^7.2.0",
"@types/jest": "^26.0.0",
"@types/react": "^16.9.19",
"@types/react-native": "0.62.13",
Expand All @@ -65,6 +66,7 @@
"react": "16.13.1",
"react-native": "0.63.4",
"react-native-builder-bob": "^0.18.0",
"react-test-renderer": "^17.0.2",
"release-it": "^14.2.2",
"typescript": "^4.1.3"
},
Expand Down
95 changes: 95 additions & 0 deletions src/__tests__/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<MirrorLists /> should renders correctly 1`] = `
<View
style={
Array [
Object {
"flex": 1,
"flexDirection": "column",
},
]
}
>
<RCTScrollView
decelerationRate="fast"
horizontal={true}
onMomentumScrollEnd={[Function]}
onScroll={[Function]}
onScrollBeginDrag={[Function]}
scrollEventThrottle={1}
showsHorizontalScrollIndicator={false}
snapToInterval={0}
style={
Object {
"flexGrow": 0,
}
}
>
<View>
<View
style={
Object {
"width": 375,
}
}
/>
<View
onLayout={[Function]}
>
<Image
source={
Object {
"uri": "https://avatars.githubusercontent.com/u/42688281?v=4",
}
}
style={
Object {
"borderRadius": 32,
"height": 64,
"marginHorizontal": 12,
"marginVertical": 8,
"width": 64,
}
}
/>
</View>
<View
style={
Object {
"width": 375,
}
}
/>
</View>
</RCTScrollView>
<RCTScrollView
decelerationRate="fast"
onLayout={[Function]}
onMomentumScrollEnd={[Function]}
onScroll={[Function]}
onScrollBeginDrag={[Function]}
scrollEventThrottle={1}
snapToInterval={0}
style={
Object {
"flex": 1,
}
}
>
<View>
<View
style={
Object {
"height": 0,
}
}
>
<Text>
This guy is really amazing
</Text>
</View>
</View>
</RCTScrollView>
</View>
`;
73 changes: 72 additions & 1 deletion src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,72 @@
it.todo('write a test');
import React from 'react';
import { Image, Text } from 'react-native';
import { render } from '@testing-library/react-native';

import { MirrorLists } from '../index';

describe('<MirrorLists />', () => {
test('should renders correctly', () => {
const mockedData = [
{
id: Math.random(),
image: 'https://avatars.githubusercontent.com/u/42688281?v=4',
description: 'This guy is really amazing',
},
];

const container = render(
<MirrorLists
data={mockedData}
keyExtractor={({ item }) => item.id.toString()}
horizontalRenderItem={({ item }) => (
<Image
source={{ uri: item.image }}
style={{
width: 64,
height: 64,
marginHorizontal: 12,
marginVertical: 8,
borderRadius: 32,
}}
/>
)}
verticalRenderItem={({ item }) => <Text>{item.description}</Text>}
/>
);
expect(container).toMatchSnapshot();
});

test('should renders correctly with image and description', () => {
const mockedData = [
{
id: 1,
image: 'https://avatars.githubusercontent.com/u/42688281?v=4',
description: 'This guy is really amazing',
},
];

const container = render(
<MirrorLists
data={mockedData}
keyExtractor={({ item }) => item.id.toString()}
horizontalRenderItem={({ item }) => (
<Image
testID="avatar"
source={{ uri: item.image }}
style={{
width: 64,
height: 64,
marginHorizontal: 12,
marginVertical: 8,
borderRadius: 32,
}}
/>
)}
verticalRenderItem={({ item }) => <Text>{item.description}</Text>}
/>
);

expect(container.getByTestId('avatar')).toBeTruthy();
expect(container.getByText('This guy is really amazing')).toBeTruthy();
});
});
37 changes: 35 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,13 @@
dependencies:
defer-to-connect "^2.0.0"

"@testing-library/react-native@^7.2.0":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@testing-library/react-native/-/react-native-7.2.0.tgz#e5ec5b0974e4e5f525f8057563417d1e9f820d96"
integrity sha512-rDKzJjAAeGgyoJT0gFQiMsIL09chdWcwZyYx6WZHMgm2c5NDqY52hUuyTkzhqddMYWmSRklFphSg7B2HX+246Q==
dependencies:
pretty-format "^26.0.1"

"@tootallnate/once@1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
Expand Down Expand Up @@ -7570,7 +7577,7 @@ pretty-format@^25.1.0, pretty-format@^25.2.0:
ansi-styles "^4.0.0"
react-is "^16.12.0"

pretty-format@^26.0.0, pretty-format@^26.6.2:
pretty-format@^26.0.0, pretty-format@^26.0.1, pretty-format@^26.6.2:
version "26.6.2"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-26.6.2.tgz#e35c2705f14cb7fe2fe94fa078345b444120fc93"
integrity sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==
Expand Down Expand Up @@ -7721,7 +7728,7 @@ react-is@^16.12.0, react-is@^16.8.1, react-is@^16.8.4:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

react-is@^17.0.1:
"react-is@^16.12.0 || ^17.0.0", react-is@^17.0.1, react-is@^17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
Expand Down Expand Up @@ -7791,6 +7798,24 @@ react-refresh@^0.4.0:
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.4.3.tgz#966f1750c191672e76e16c2efa569150cc73ab53"
integrity sha512-Hwln1VNuGl/6bVwnd0Xdn1e84gT/8T9aYNL+HAKDArLCS7LWjwr7StE30IEYbIkx0Vi3vs+coQxe+SQDbGbbpA==

react-shallow-renderer@^16.13.1:
version "16.14.1"
resolved "https://registry.yarnpkg.com/react-shallow-renderer/-/react-shallow-renderer-16.14.1.tgz#bf0d02df8a519a558fd9b8215442efa5c840e124"
integrity sha512-rkIMcQi01/+kxiTE9D3fdS959U1g7gs+/rborw++42m1O9FAQiNI/UNRZExVUoAOprn4umcXf+pFRou8i4zuBg==
dependencies:
object-assign "^4.1.1"
react-is "^16.12.0 || ^17.0.0"

react-test-renderer@^17.0.2:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-17.0.2.tgz#4cd4ae5ef1ad5670fc0ef776e8cc7e1231d9866c"
integrity sha512-yaQ9cB89c17PUb0x6UfWRs7kQCorVdHlutU1boVPEsB8IDZH6n9tHxMacc3y0JoXOJUsZb/t/Mb8FUWMKaM7iQ==
dependencies:
object-assign "^4.1.1"
react-is "^17.0.2"
react-shallow-renderer "^16.13.1"
scheduler "^0.20.2"

react@16.13.1:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
Expand Down Expand Up @@ -8233,6 +8258,14 @@ scheduler@0.19.1:
loose-envify "^1.1.0"
object-assign "^4.1.1"

scheduler@^0.20.2:
version "0.20.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

semver-compare@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
Expand Down

0 comments on commit d7dcb04

Please sign in to comment.