Skip to content

Commit

Permalink
Merge pull request #1 from amplexus/react-17-support
Browse files Browse the repository at this point in the history
neptunian#205 support for react 17
  • Loading branch information
amplexus authored Nov 7, 2021
2 parents 0bb8e4c + 089437b commit 7689bae
Show file tree
Hide file tree
Showing 7 changed files with 32,423 additions and 9,124 deletions.
35 changes: 17 additions & 18 deletions __test__/Gallery.test.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import React from 'react';
import Gallery from '../src/Gallery';
import { photos } from './test-photo-data';
import { mount } from 'enzyme';
import React from "react";
import Gallery from "../src/Gallery";
import { photos } from "./test-photo-data";
import { mount } from "enzyme";

const handleClick = jest.fn();

describe('Gallery', () => {
describe("Gallery", () => {
let wrapper;
afterEach(() => {
if (wrapper && wrapper.length > 0) {
wrapper.unmount();
}
});

it('it matches correct snapshot', () => {
wrapper = mount(<Gallery photos={photos} onClick={handleClick} />);
it("it matches correct snapshot", () => {
wrapper = mount(<Gallery photos={photos} onClick={handleClick} />, { attachTo: document.body });
expect(wrapper).toMatchSnapshot();
});

it('calls onClick handler', () => {
wrapper = mount(<Gallery photos={photos} onClick={handleClick} />);
wrapper
.find('img')
.first()
.simulate('click');
it("calls onClick handler", () => {
wrapper = mount(<Gallery photos={photos} onClick={handleClick} />, { attachTo: document.body });
wrapper.find("img").first().simulate("click");
expect(handleClick).toHaveBeenCalled();
});

it('renders correctly with direction set to column', () => {
wrapper = mount(<Gallery photos={photos} direction={'column'} />);
it("renders correctly with direction set to column", () => {
wrapper = mount(<Gallery photos={photos} direction={"column"} />, { attachTo: document.body });
expect(wrapper).toMatchSnapshot();
});

it('renders correctly with a column function', () => {
const columns = jest.fn(_ => 3);
wrapper = mount(<Gallery photos={photos} onClick={handleClick} columns={columns} direction="column" />);
it("renders correctly with a column function", () => {
const columns = jest.fn((_) => 3);
wrapper = mount(<Gallery photos={photos} onClick={handleClick} columns={columns} direction="column" />, {
attachTo: document.body,
});
expect(columns).toBeCalledWith(1140);
});
});
6 changes: 3 additions & 3 deletions __test__/jestsetup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { configure } from "enzyme";
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";

configure({ adapter: new Adapter() });
configure({ adapter: new Adapter() });
7 changes: 4 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = {
verbose: true,
testEnvironment: "jsdom",
collectCoverage: true,
collectCoverageFrom: ['src/**/*.js'],
setupFiles: ['./__test__/shims.js', './__test__/jestsetup.js'],
snapshotSerializers: ['enzyme-to-json/serializer'],
collectCoverageFrom: ["src/**/*.js"],
setupFiles: ["./__test__/shims.js", "./__test__/jestsetup.js"],
snapshotSerializers: ["enzyme-to-json/serializer"],
};
Loading

0 comments on commit 7689bae

Please sign in to comment.