Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/react-arborist/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const config = {
// snapshotSerializers: [],

// The test environment that will be used for testing
// testEnvironment: "jest-environment-node",
testEnvironment: "jsdom",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},
Expand Down
6 changes: 6 additions & 0 deletions modules/react-arborist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@
"react-dom": ">= 16.14"
},
"devDependencies": {
"@testing-library/dom": "^9.3.0",
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.5.11",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.0",
"@types/react-window": "^1.8.8",
"@types/use-sync-external-store": "^0.0.6",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"npm-run-all": "^4.1.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^5.0.5",
"ts-jest": "^29.1.1",
"typescript": "^5.6.0"
Expand Down
44 changes: 44 additions & 0 deletions modules/react-arborist/src/components/provider.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { createRef } from "react";
import { act, render } from "@testing-library/react";
import { Tree } from "./tree";
import { TreeApi } from "../interfaces/tree-api";

type Datum = { id: string; name: string; children?: Datum[] };

const data: Datum[] = [
{
id: "1",
name: "root",
children: [
{ id: "2", name: "a" },
{ id: "3", name: "b", children: [{ id: "4", name: "c" }] },
],
},
];

test("imperative tree.update() props survive node toggles (#228)", () => {
const ref = createRef<TreeApi<Datum> | undefined>();
render(
<Tree<Datum>
data={data}
ref={ref}
rowHeight={24}
openByDefault={false}
/>
);
const api = ref.current!;
expect(api.rowHeight).toBe(24);

act(() => {
api.update({ ...api.props, rowHeight: 48 });
});
expect(api.rowHeight).toBe(48);

/* Opening a node dispatches a redux action that changes state.nodes.open.
Before #337, the open-state effect re-ran api.update(treeProps), reverting
rowHeight to 24. */
act(() => {
api.open("1");
});
expect(api.rowHeight).toBe(48);
});
Loading
Loading