Open
Description
Describe the bug
In our app we have some unit tests to check that all of our Storybooks are rendering correctly. We have recently been updating our React Native version to the latest version (0.73.1), but since then our unit test has begun failing with this error:
FAIL __tests__/storybooks/index.test.js
β Test suite failed to run
TypeError: Cannot set properties of undefined (setting 'onkeydown')
37 | });
38 |
> 39 | configure(() => {
| ^
40 | require('../../storybook/stories');
41 | }, module);
42 |
at PreviewWeb.setupListeners (node_modules/@storybook/preview-web/dist/cjs/PreviewWeb.js:145:29)
at PreviewWeb.setupListeners [as initialize] (node_modules/@storybook/preview-web/dist/cjs/Preview.js:137:12)
at initialize (node_modules/@storybook/react-native/dist/index.js:1545:17)
at Object.<anonymous> (__tests__/storybooks/index.test.js:39:10)
at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at asyncGeneratorStep (node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)
To Reproduce
Implement test form snippet below in a RN app (version 0.73.1) using storybooks
Expected behavior
Test should run rather than fail
Code snippets
Here is a basic reproduction of the test we are running that is failing:
// Always need to import this at every entry point, otherwise some custom yup validators fail.
import '~/yup-methods';
import { NativeModules } from 'react-native';
import {
getStorybook,
configure,
getStorybookUI,
} from '@storybook/react-native';
import { render } from '@testing-library/react-native';
// Need to mock a bunch of things to render the stories within Jest.
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
jest.mock('react-native-video', () => 'Video');
global.fetch = jest.fn();
NativeModules.RNViewShot = jest.fn();
jest.mock('react-native-share', () => ({
Social: {},
}));
jest.mock('react-native-keyboard-aware-scroll-view', () => {
const KeyboardAwareScrollView = require('react-native').ScrollView;
return { KeyboardAwareScrollView };
});
jest.mock('react-native-dropdown-picker', () => {
const MockedDropdownPicker = () => {};
return jest.fn(() => MockedDropdownPicker);
});
configure(() => {
require('../../storybook/stories');
}, module);
getStorybookUI({
asyncStorage: null,
// Must disable, otherwise Storybook crashes in Jest.
disableWebsockets: true,
});
describe('Storybook', () => {
getStorybook().forEach((storyFile) => {
const storyFileName = storyFile.fileName.split('/storybook/stories/')[1];
describe(storyFile.kind + ': ' + storyFileName, () => {
storyFile.stories.forEach((story) => {
//Disable test for appointment confirmation email preview as html causes crash
it(`${story.name} render correctly`, () => {
expect(() => render(story.render())).not.toThrow();
});
});
});
});
});
System:
Storybook Environment Info:
System:
OS: macOS 14.2
CPU: (10) arm64 Apple M1 Pro
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm <----- active
Browsers:
Chrome: 120.0.6099.129
Safari: 17.2
npmPackages:
@storybook/react-native: ^6.5.6 => 6.5.7
@storybook/react-native-server: ^5.3.23 => 5.3.23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
No labels