Skip to content

Commit

Permalink
fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CompuIves committed Jan 31, 2025
1 parent f520d59 commit 0feb843
Show file tree
Hide file tree
Showing 11 changed files with 2,067 additions and 1,686 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.8",
"jest": "^27.4.5",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"lerna": "^7.4.1",
"lerna-changelog": "^2.2.0",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"react-test-renderer": "^18.1.0",
"rollup": "^3.9.1",
"rollup-plugin-string": "^3.0.0",
"turbo": "^1.5.5"
Expand Down
10 changes: 10 additions & 0 deletions sandpack-react/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
setupFilesAfterEnv: ["<rootDir>/src/setup.jest.ts"],
testEnvironment: "jsdom",
testEnvironmentOptions: {
customExportConditions: [""],
},
globals: {
"process.env.TEST_ENV": "true",
},
};
3 changes: 3 additions & 0 deletions sandpack-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
"@codesandbox/sandpack-themes": "^2.0.21",
"@storybook/react": "^7.5.1",
"@storybook/react-vite": "^7.5.1",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.2.0",
"@testing-library/react-hooks": "8.0.1",
"@types/fs-extra": "^5.0.4",
"@types/glob": "^5.0.35",
Expand Down
21 changes: 7 additions & 14 deletions sandpack-react/src/components/CodeEditor/CodeEditor.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @jest-environment jsdom
*/
import { act } from "@testing-library/react-hooks";
import { act, render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import React from "react";
import { create } from "react-test-renderer";

import { SandpackProvider } from "../../";

Expand All @@ -13,7 +13,7 @@ describe("read-only", () => {
jest.useFakeTimers();

it("should render the read-only flag", () => {
const { root } = create(
render(
<SandpackProvider>
<SandpackCodeEditor readOnly />
</SandpackProvider>
Expand All @@ -23,13 +23,12 @@ describe("read-only", () => {
jest.runAllTimers();
});

const readOnlyFlag = root.findByProps({ "data-testId": "read-only" });

expect(readOnlyFlag.props.children).toBe("Read-only");
const readOnlyFlag = screen.getByTestId("read-only");
expect(readOnlyFlag).toHaveTextContent("Read-only");
});

it("should not render the read-only flag, when showReadOnly is false", () => {
const { root } = create(
render(
<SandpackProvider>
<SandpackCodeEditor showReadOnly={false} readOnly />
</SandpackProvider>
Expand All @@ -39,12 +38,6 @@ describe("read-only", () => {
jest.runAllTimers();
});

try {
root.findByProps({ "data-testId": "read-only" });
} catch (err) {
expect(err.message).toBe(
'No instances found with props: {"data-testId":"read-only"}'
);
}
expect(screen.queryByTestId("read-only")).not.toBeInTheDocument();
});
});
3 changes: 2 additions & 1 deletion sandpack-react/src/components/CodeEditor/CodeMirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ export const CodeMirror = React.forwardRef<CodeMirrorRef, CodeMirrorProps>(
[decorators]
);

const useStaticReadOnly = readOnly && decorators?.length === 0;
const useStaticReadOnly =
readOnly && (decorators?.length === 0 || decorators === undefined);

React.useEffect(() => {
if (!wrapper.current || !shouldInitEditor || useStaticReadOnly) {
Expand Down
Loading

0 comments on commit 0feb843

Please sign in to comment.