Skip to content

Commit 584eb94

Browse files
Merge pull request #834 from GetStream/fix-tests-dev
test(unit): Fix old unit tests
2 parents 48c5cca + edf9009 commit 584eb94

File tree

66 files changed

+7864
-6112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+7864
-6112
lines changed

.github/workflows/check-pr.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Check PR
1+
name: Lint & Unit Tests
22

33
on:
44
pull_request:
@@ -22,3 +22,5 @@ jobs:
2222
run: yarn --frozen-lockfile && yarn bootstrap-ci
2323
- name: Lint
2424
run: yarn lint
25+
- name: Test
26+
run: yarn test:unit

examples/SampleApp/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"bootstrap": "yarn install",
1919
"bootstrap-ci": "yarn install --frozen-lockfile",
2020
"release": "FILTER_PATH='examples/SampleApp' TAG_FORMAT=$npm_package_name'@v${version}' node ../../release/prod",
21-
"release-next": "echo \"Skipping next release for SampleApp\""
21+
"release-next": "echo \"Skipping next release for SampleApp\"",
22+
"test:unit": "echo \"Skipping unit tests for SampleApp\""
2223
},
2324
"dependencies": {
2425
"@react-native-async-storage/async-storage": "1.15.6",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"bootstrap": "yarn lerna-workspaces run bootstrap",
3232
"bootstrap-ci": "yarn lerna-workspaces run bootstrap-ci",
3333
"lint": "yarn lerna-workspaces run lint",
34+
"test:unit": "yarn lerna-workspaces run test:unit",
3435
"build": "yarn lerna-workspaces run build"
3536
}
3637
}

package/__mocks__/react-native.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
import * as ReactNative from 'react-native';
3+
4+
export * from 'react-native';
5+
6+
export const Image = ReactNative.Image;
7+
8+
Image.prefetch = () => Promise.resolve();
9+
10+
export const FlatList = function MockedFlatList(props) {
11+
if (!props.data.length && props.ListEmptyComponent)
12+
return <ReactNative.View testID={props.testID}>{props.ListEmptyComponent}</ReactNative.View>;
13+
14+
const items = props.data.map((item, index) => {
15+
const key = props.keyExtractor(item, index);
16+
return <ReactNative.View key={key}>{props.renderItem({ index, item })}</ReactNative.View>;
17+
});
18+
return <ReactNative.View testID={props.testID}>{items}</ReactNative.View>;
19+
};
20+
21+
export default Object.setPrototypeOf(
22+
{
23+
FlatList,
24+
Image,
25+
},
26+
ReactNative,
27+
);

package/babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = (api) => {
2626
},
2727
],
2828
'module-resolver',
29+
'react-native-reanimated/plugin',
2930
],
3031
presets: ['@babel/env', 'module:metro-react-native-babel-preset', '@babel/preset-typescript'],
3132
};

package/jest-setup.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,15 @@ registerNativeHandlers({
3636
triggerHaptic: () => null,
3737
});
3838

39-
jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock'));
39+
require('react-native-reanimated/lib/reanimated2/jestUtils').setUpTests();
40+
41+
jest.mock('@gorhom/bottom-sheet', () => {
42+
const react = require('react-native');
43+
return {
44+
__esModule: true,
45+
default: react.View,
46+
BottomSheetScrollView: react.ScrollView,
47+
BottomSheetFlatList: react.FlatList,
48+
};
49+
});
50+
// jest.mock('react-native-reanimated', () => require('react-native-reanimated/mock'));

package/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// eslint-disable-next-line no-undef
22
module.exports = {
3+
testEnvironment: 'jsdom',
4+
35
moduleNameMapper: {
46
'mock-builders(.*)$': '<rootDir>/src/mock-builders$1',
57
},
@@ -11,6 +13,7 @@ module.exports = {
1113
],
1214
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
1315
testPathIgnorePatterns: ['/node_modules/', '/examples/', '__snapshots__'],
16+
transformIgnorePatterns: ['node_modules/!(react-native-reanimated)'],
1417
testRegex: [
1518
/**
1619
* If you want to test single file, mention it here

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"prepare-distribution": "cd examples/SampleApp && npm version patch && react-native-version && git add ./ && git commit -m 'Bump build version' --no-verify",
3737
"prettier": "prettier --list-different '**/*.{js,ts,tsx,md,json}' .eslintrc.json ../.prettierrc .babelrc",
3838
"prettier-fix": "prettier --write '**/*.{js,ts,tsx,md,json}' .eslintrc.json ../.prettierrc .babelrc",
39-
"test": "TZ=UTC jest",
39+
"test:unit": "TZ=UTC jest",
4040
"validate-translations": "node bin/validate-translations.js",
4141
"get-version": "echo $npm_package_version",
4242
"version": "bash ./bin/before-tag.sh",

package/src/components/Attachment/Gallery.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const GalleryImage: React.FC<
6161
: uri.replace('h=%2A', `h=${PixelRatio.getPixelSizeForLayoutSize(Number(height))}`)
6262
: uri,
6363
}}
64+
testID='image-attachment-single'
6465
/>
6566
);
6667
};

package/src/components/Attachment/__tests__/Attachment.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('Attachment', () => {
5050
const { getByTestId } = render(getAttachmentComponent({ attachment }));
5151

5252
await waitFor(() => {
53-
expect(getByTestId('card-attachment')).toBeTruthy();
53+
expect(getByTestId('giphy-attachment')).toBeTruthy();
5454
});
5555
});
5656

@@ -59,7 +59,7 @@ describe('Attachment', () => {
5959
const { getByTestId } = render(getAttachmentComponent({ attachment }));
6060

6161
await waitFor(() => {
62-
expect(getByTestId('card-attachment')).toBeTruthy();
62+
expect(getByTestId('giphy-attachment')).toBeTruthy();
6363
});
6464
});
6565

@@ -80,7 +80,7 @@ describe('Attachment', () => {
8080
const { getByTestId } = render(getAttachmentComponent({ attachment }));
8181

8282
await waitFor(() => {
83-
expect(getByTestId('image-attachment-single')).toBeTruthy();
83+
expect(getByTestId('image-multiple')).toBeTruthy();
8484
});
8585
});
8686

@@ -97,12 +97,12 @@ describe('Attachment', () => {
9797
});
9898

9999
it('should call actionHandler on click', async () => {
100-
const actionHandler = jest.fn();
100+
const handleAction = jest.fn();
101101
const action = generateAttachmentAction();
102102
const { getByTestId } = render(
103103
getActionComponent({
104-
actionHandler,
105104
actions: [action],
105+
handleAction,
106106
}),
107107
);
108108

@@ -116,7 +116,7 @@ describe('Attachment', () => {
116116
fireEvent.press(getByTestId(`attachment-actions-button-${action.name}`));
117117

118118
await waitFor(() => {
119-
expect(actionHandler).toHaveBeenCalledTimes(2);
119+
expect(handleAction).toHaveBeenCalledTimes(2);
120120
});
121121
});
122122

0 commit comments

Comments
 (0)