-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use in Storybook 5.2 Component Story Format (CSF)? #121
Comments
Example on how I got it to work. |
I cant get mount to work. Shallow works fine but mount always says "inst is null" I've tried a bunch of different react versions but cant figure whats wrong. My steps
My code
|
Weird works now. |
@philipbeadle do you know what caused it to work? I'm having the same problem where |
I set up a setupTests.js import { configure as enzymeConfigure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
enzymeConfigure({ adapter: new Adapter() }); Moved my tests to a separate file import React from 'react';
import { mount } from 'enzyme';
import { MessageList } from './index';
import { testMessages } from '../../testData/messageList';
export const noMessageListTests = describe('No messages', function () {
let props = {
messages: []
}
const component = (
<MessageList {...props}/>
);
it('Renders witout crashing', function () {
mount(component);
});
it('Does not show any messages', function () {
let wrap = mount(component);
expect(wrap.find('Message').length).toEqual(0)
});
it('Shows the no messages message', function () {
let wrap = mount(component);
expect(wrap.find('h2').text()).toContain('No Messages Yet');
});
}) and import the tests import React from 'react';
import { action } from '@storybook/addon-actions';
import { MessageList } from '../src/components/MessageList/index';
import { specs } from 'storybook-addon-specifications';
import { noMessageListTests } from '../src/components/MessageList/index.test'
import { messageListTests } from '../src/components/MessageList/index.test'
import { testMessages } from '../src/testData/messageList';
export default {
title: 'Message List'
};
export const noMessages = () => {
let props = {
messages: []
}
const story = (
<MessageList {...props} />
);
specs(() => noMessageListTests);
return story;
}
noMessages.story = {
name: 'No messages'
} Also added a test.js to the .storybook folder import { describe, it, beforeEach } from 'storybook-addon-specifications';
import expect from 'expect';
import jest from 'jest-mock';
import { shallow, mount } from 'enzyme';
import { configure as enzymeConfigure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
enzymeConfigure({ adapter: new Adapter() });
window.describe = describe;
window.beforeEach = beforeEach;
window.it = it;
window.expect = expect;
window.jest = jest;
window.shallow = shallow;
window.mount = mount; and import that in the config.js import { configure } from '@storybook/react';
import './test'
configure(require.context('../stories', true, /\.stories\.js$/), module); Now it all works and I can run my tests in jest as well. |
@philipbeadle Just wanted to say thanks, been working through this setup for a few hours and nothing was working until I followed your post. And as an added bonus my story files don't get cluttered with the tests, nice and clean. |
Hello, I am currently trying to get this to work on CSF and am having issues setting up inside with errors coming from other modules. The project I am working on currently is using the method where we have no config.js but use the main.js file Any tips or advice? My main issue is I cannot get the expect function to work. It causes an error in my build |
@andrewcorliss Did you ever find a solution? I'm having the same issue with Edit: I made a brand new React app and added Storybook using these steps from @philipbeadle above and it's working for me now! I also had problems with |
I'm working on support CSF format and support for storybook 6. Described in #123. |
https://storybook.js.org/docs/formats/component-story-format/
The text was updated successfully, but these errors were encountered: