test: Reduce memory usage by not requiring stores into all (#2265)
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
import "../stores";
|
||||||
import { shallow } from "enzyme";
|
import { shallow } from "enzyme";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { DEFAULT_PAGINATION_LIMIT } from "stores/BaseStore";
|
import { DEFAULT_PAGINATION_LIMIT } from "stores/BaseStore";
|
||||||
@ -6,14 +7,20 @@ import { runAllPromises } from "../test/support";
|
|||||||
import PaginatedList from "./PaginatedList";
|
import PaginatedList from "./PaginatedList";
|
||||||
|
|
||||||
describe("PaginatedList", () => {
|
describe("PaginatedList", () => {
|
||||||
|
const render = () => null;
|
||||||
|
|
||||||
it("with no items renders nothing", () => {
|
it("with no items renders nothing", () => {
|
||||||
const list = shallow(<PaginatedList items={[]} />);
|
const list = shallow(<PaginatedList items={[]} renderItem={render} />);
|
||||||
expect(list).toEqual({});
|
expect(list).toEqual({});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("with no items renders empty prop", () => {
|
it("with no items renders empty prop", () => {
|
||||||
const list = shallow(
|
const list = shallow(
|
||||||
<PaginatedList items={[]} empty={<p>Sorry, no results</p>} />
|
<PaginatedList
|
||||||
|
items={[]}
|
||||||
|
empty={<p>Sorry, no results</p>}
|
||||||
|
renderItem={render}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
expect(list.text()).toEqual("Sorry, no results");
|
expect(list.text()).toEqual("Sorry, no results");
|
||||||
});
|
});
|
||||||
@ -22,7 +29,14 @@ describe("PaginatedList", () => {
|
|||||||
const fetch = jest.fn();
|
const fetch = jest.fn();
|
||||||
const options = { id: "one" };
|
const options = { id: "one" };
|
||||||
|
|
||||||
shallow(<PaginatedList items={[]} fetch={fetch} options={options} />);
|
shallow(
|
||||||
|
<PaginatedList
|
||||||
|
items={[]}
|
||||||
|
fetch={fetch}
|
||||||
|
options={options}
|
||||||
|
renderItem={render}
|
||||||
|
/>
|
||||||
|
);
|
||||||
expect(fetch).toHaveBeenCalledWith({
|
expect(fetch).toHaveBeenCalledWith({
|
||||||
...options,
|
...options,
|
||||||
limit: DEFAULT_PAGINATION_LIMIT,
|
limit: DEFAULT_PAGINATION_LIMIT,
|
||||||
@ -35,7 +49,12 @@ describe("PaginatedList", () => {
|
|||||||
const fetch = jest.fn().mockReturnValue(fetchedItems);
|
const fetch = jest.fn().mockReturnValue(fetchedItems);
|
||||||
|
|
||||||
const list = shallow(
|
const list = shallow(
|
||||||
<PaginatedList items={[]} fetch={fetch} options={{ id: "one" }} />
|
<PaginatedList
|
||||||
|
items={[]}
|
||||||
|
fetch={fetch}
|
||||||
|
options={{ id: "one" }}
|
||||||
|
renderItem={render}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
await runAllPromises();
|
await runAllPromises();
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
import localStorage from '../../__mocks__/localStorage';
|
import localStorage from '../../__mocks__/localStorage';
|
||||||
import Enzyme from "enzyme";
|
import Enzyme from "enzyme";
|
||||||
import Adapter from "enzyme-adapter-react-16";
|
import Adapter from "enzyme-adapter-react-16";
|
||||||
import "../stores";
|
|
||||||
|
|
||||||
Enzyme.configure({ adapter: new Adapter() });
|
Enzyme.configure({ adapter: new Adapter() });
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
// @flow
|
// @flow
|
||||||
export const runAllPromises = () => new Promise(setImmediate);
|
export const runAllPromises = () => new Promise<void>(setImmediate);
|
||||||
|
Reference in New Issue
Block a user