You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
E:\blog\blogger\src\app\test\utilistest\Table.test.tsx:15
(0, react_1.render)(<components_1.AnalysisTable rows={mockData}/>);
^
SyntaxError: Unexpected token '<'
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
(node:33364) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)
(node:40984) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)
PASS src/app/test/utilistest/calculateReadTime.test.ts (14.124 s)
(node:14708) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)
PASS src/app/test/utilistest/DateDifference.test.ts (14.655 s)
(node:28228) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead.
(Use node --trace-deprecation ... to show where the warning was created)
PASS src/app/test/utilistest/FilterData.test.ts (14.662 s)
Test Suites: 1 failed, 3 passed, 4 total
Tests: 13 passed, 13 total
Snapshots: 0 total
Time: 17.113 s, estimated 29 s
Ran all test suites.
PS E:\blog\blogger>
test file
import { fireEvent, render, screen } from "@testing-library/react";
import { AnalysisTable } from "@/ui/components";
Version
29.7.0
Steps to reproduce
https://github.com/Navani001/blogger.git
npm i -f
Expected behavior
Test suite failed to run
(node:33364) [DEP0040] DeprecationWarning: The
punycode
module is deprecated. Please use a userland alternative instead.(Use
node --trace-deprecation ...
to show where the warning was created)(node:40984) [DEP0040] DeprecationWarning: The
punycode
module is deprecated. Please use a userland alternative instead.(Use
node --trace-deprecation ...
to show where the warning was created)PASS src/app/test/utilistest/calculateReadTime.test.ts (14.124 s)
(node:14708) [DEP0040] DeprecationWarning: The
punycode
module is deprecated. Please use a userland alternative instead.(Use
node --trace-deprecation ...
to show where the warning was created)PASS src/app/test/utilistest/DateDifference.test.ts (14.655 s)
(node:28228) [DEP0040] DeprecationWarning: The
punycode
module is deprecated. Please use a userland alternative instead.(Use
node --trace-deprecation ...
to show where the warning was created)PASS src/app/test/utilistest/FilterData.test.ts (14.662 s)
Test Suites: 1 failed, 3 passed, 4 total
Tests: 13 passed, 13 total
Snapshots: 0 total
Time: 17.113 s, estimated 29 s
Ran all test suites.
PS E:\blog\blogger>
test file
import { fireEvent, render, screen } from "@testing-library/react";
import { AnalysisTable } from "@/ui/components";
const mockData = [
{ id: 1, title: "Test 1", url: "http://test1.com", status: "active", desc: "Description 1" },
{ id: 2, title: "Test 2", url: "http://test2.com", status: "inactive", desc: "Description 2" },
{ id: 3, title: "Test 3", url: "http://test3.com", status: "active", desc: "Description 3" },
{ id: 4, title: "Test 4", url: "http://test4.com", status: "inactive", desc: "Description 4" },
{ id: 5, title: "Test 5", url: "http://test5.com", status: "active", desc: "Description 5" },
{ id: 6, title: "Test 6", url: "http://test6.com", status: "inactive", desc: "Description 6" },
];
describe("AnalysisTable", () => {
it("renders table with correct headers", () => {
render();
expect(screen.getByText("Title")).toBeInTheDocument();
expect(screen.getByText("Url")).toBeInTheDocument();
expect(screen.getByText("Status")).toBeInTheDocument();
expect(screen.getByText("Desc")).toBeInTheDocument();
});
it("renders correct number of rows per page", () => {
render();
const tableRows = screen.getAllByRole("row");
// +1 for header row
expect(tableRows.length).toBe(6); // 5 data rows + 1 header row
});
it("handles pagination correctly", () => {
render();
const nextPageButton = screen.getByRole("button", { name: /next page/i });
fireEvent.click(nextPageButton);
expect(screen.getByText("Test 6")).toBeInTheDocument();
});
it("renders view button when isview is true", () => {
const handleView = jest.fn();
render();
const viewButtons = screen.getAllByRole("button", { name: /view/i });
expect(viewButtons.length).toBe(5); // 5 rows per page
});
it("handles empty data correctly", () => {
render();
expect(screen.getByRole("table")).toBeInTheDocument();
});
it("removes specified columns correctly", () => {
render(<AnalysisTable rows={mockData} coloumn_remove={['id', 'status']} />);
expect(screen.queryByText("Id")).not.toBeInTheDocument();
expect(screen.queryByText("Status")).not.toBeInTheDocument();
});
it("changes rows per page correctly", () => {
render();
const select = screen.getByRole("combobox");
fireEvent.change(select, { target: { value: "10" } });
const tableRows = screen.getAllByRole("row");
// +1 for header row
expect(tableRows.length).toBe(7); // 6 data rows + 1 header row
});
});
jest.config.ts
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jsdom',
testMatch: ["/tests//.ts?(x)", "**/?(.)+(test).ts?(x)"],
transform: {
"^.+\.(js|ts)$": "ts-jest",
},
transformIgnorePatterns: [
"/node_modules/(?![@autofiy/autofiyable|@autofiy/property]).+\.js$",
"/node_modules/(?![@autofiy/autofiyable|@autofiy/property]).+\.ts$",
"/node_modules/(?![@autofiy/autofiyable|@autofiy/property]).+\.tsx$",
],
}
Actual behavior
not working
Additional context
No response
Environment
The text was updated successfully, but these errors were encountered: