Skip to content

Commit

Permalink
Tweaked Lint rule and fixed a few warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Dec 15, 2023
1 parent a17f89b commit b2df1fc
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 14 deletions.
5 changes: 2 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ module.exports = {
},
plugins: ["react"],
rules: {
"react/no-did-update-set-state": "off",
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
"react/no-did-update-set-state": "off",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/no-explicit-any": "off",
},
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@
"@babel/preset-env": "^7.22.5",
"@babel/preset-typescript": "^7.21.5",
"@preconstruct/cli": "^2.8.1",
"@types/assert": "^1.5.10",
"@types/jest": "^26.0.15",
"@types/react": "^18",
"@types/react-dom": "^18",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"assert": "^2.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.25.2",
Expand Down
64 changes: 64 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions src/ErrorBoundary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @jest-environment jsdom
*/

import assert from "assert";
import { createRef, PropsWithChildren, ReactElement, RefObject } from "react";
import { createRoot } from "react-dom/client";
import { act } from "react-dom/test-utils";
Expand All @@ -20,11 +21,13 @@ describe("ErrorBoundary", () => {
let valueToThrow: any;

beforeEach(() => {
// @ts-ignore
// @ts-expect-error This is a React internal
global.IS_REACT_ACT_ENVIRONMENT = true;

// Don't clutter the console with expected error text
jest.spyOn(console, "error").mockImplementation(() => {});
jest.spyOn(console, "error").mockImplementation(() => {
// No-op
});

container = document.createElement("div");
root = createRoot(container);
Expand Down Expand Up @@ -202,7 +205,8 @@ describe("ErrorBoundary", () => {
expect(lastRenderedResetErrorBoundary).not.toBeNull();
act(() => {
shouldThrow = false;
lastRenderedResetErrorBoundary!();
assert(lastRenderedResetErrorBoundary !== null);
lastRenderedResetErrorBoundary();
});

expect(container.textContent).toBe("Content");
Expand Down Expand Up @@ -270,7 +274,8 @@ describe("ErrorBoundary", () => {

act(() => {
shouldThrow = false;
lastRenderedResetErrorBoundary!();
assert(lastRenderedResetErrorBoundary !== null);
lastRenderedResetErrorBoundary();
});

expect(container.textContent).toBe("Content");
Expand Down
13 changes: 9 additions & 4 deletions src/useErrorBoundary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @jest-environment jsdom
*/

import assert from "assert";
import { createRoot } from "react-dom/client";
import { act } from "react-dom/test-utils";
import { ErrorBoundary } from "./ErrorBoundary";
Expand All @@ -12,11 +13,13 @@ describe("useErrorBoundary", () => {
let lastRenderedUseErrorBoundaryApi: UseErrorBoundaryApi<Error> | null = null;

beforeEach(() => {
// @ts-ignore
// @ts-expect-error This is a React internal
global.IS_REACT_ACT_ENVIRONMENT = true;

// Don't clutter the console with expected error text
jest.spyOn(console, "error").mockImplementation(() => {});
jest.spyOn(console, "error").mockImplementation(() => {
// No-op
});

container = document.createElement("div");
lastRenderedUseErrorBoundaryApi = null;
Expand Down Expand Up @@ -89,12 +92,14 @@ describe("useErrorBoundary", () => {
expect(container.textContent).toBe("Child");

act(() => {
showBoundary!(new Error("Example"));
assert(showBoundary !== null);
showBoundary(new Error("Example"));
});
expect(container.textContent).toBe("Error");

act(() => {
resetBoundary!();
assert(resetBoundary !== null);
resetBoundary();
});
expect(container.textContent).toBe("Child");
});
Expand Down
10 changes: 7 additions & 3 deletions src/withErrorBoundary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ describe("withErrorBoundary", () => {
let valueToThrow: any;

beforeEach(() => {
// @ts-ignore
// @ts-expect-error This is a React internal
global.IS_REACT_ACT_ENVIRONMENT = true;

// Don't clutter the console with expected error text
jest.spyOn(console, "error").mockImplementation(() => {});
jest.spyOn(console, "error").mockImplementation(() => {
// No-op
});

container = document.createElement("div");
root = createRoot(container);
Expand Down Expand Up @@ -58,7 +60,9 @@ describe("withErrorBoundary", () => {
type Props = { foo: string };

class Inner extends Component<Props> {
test() {}
test() {
// No-op
}
render() {
return this.props.foo;
}
Expand Down

0 comments on commit b2df1fc

Please sign in to comment.