Skip to content

Commit

Permalink
Move one storyshot test to RTL
Browse files Browse the repository at this point in the history
  • Loading branch information
tooppaaa committed Nov 3, 2020
1 parent 584c689 commit ffcd6fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Storyshots Async with 5ms timeout simulating async operation 1`] = `
<AsyncTestComponent>
<h1>
THIS IS SO DONE
</h1>
</AsyncTestComponent>
<h1>
THIS IS SO DONE
</h1>
`;
19 changes: 8 additions & 11 deletions addons/storyshots/storyshots-core/stories/storyshot.async.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import path from 'path';
import { mount } from 'enzyme';
import toJson from 'enzyme-to-json';
import { render, screen, waitFor } from '@testing-library/react';
import initStoryshots, { Stories2SnapsConverter } from '../dist';
import { TIMEOUT, EXPECTED_VALUE } from './required_with_context/Async.stories';

Expand All @@ -22,19 +21,17 @@ initStoryshots({
const storyElement = story.render();

// Mount the component
let wrapper = mount(storyElement);
const { container } = render(storyElement);

// The Async component should not contain the expected value
expect(wrapper.find('AsyncTestComponent').contains(EXPECTED_VALUE)).toBe(false);
expect(screen.queryByText(EXPECTED_VALUE)).toBeFalsy();

// wait until the "Async" component is updated
setTimeout(() => {
// Update the wrapper with the changes in the underlying component
wrapper = wrapper.update();

// Assert the expected value and the corresponding snapshot
expect(wrapper.find('AsyncTestComponent').contains(EXPECTED_VALUE)).toBe(true);
expect(toJson(wrapper)).toMatchSpecificSnapshot(snapshotFilename);
setTimeout(async () => {
await waitFor(() => {
expect(screen.getByText(EXPECTED_VALUE)).toBeInTheDocument();
expect(container.firstChild).toMatchSpecificSnapshot(snapshotFilename);
});

// finally mark test as done
done();
Expand Down

0 comments on commit ffcd6fe

Please sign in to comment.