Skip to content

Commit 1b80699

Browse files
authored
Create a separate tsconfig file to specify jsx mode for ts-jest vs next.js (#9)
Create a separate tsconfig file to specify jsx mode. Next.js requires the typescript jsx mode to be `preserve`, but ts-jest needs it to be a flavor of `react`. See: - https://www.typescriptlang.org/docs/handbook/jsx.html - https://kulshekhar.github.io/ts-jest/docs/getting-started/options/tsconfig - kulshekhar/ts-jest#63 (comment) - vercel/next.js#19155 (reply in thread)
1 parent f6e8efe commit 1b80699

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

app/jest.config.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ module.exports = {
1919
testPathIgnorePatterns: [
2020
"<rootDir>/node_modules/",
2121
],
22-
testRegex: "(/test/.*(test|spec))\\.[jt]sx?$"
22+
testRegex: "(/test/.*(test|spec))\\.[jt]sx?$",
23+
globals: {
24+
'ts-jest': {
25+
tsconfig: 'tsconfig.ts-jest.json'
26+
}
27+
}
2328
};

app/tsconfig.json

+18-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
"compilerOptions": {
33
"baseUrl": ".",
44
"paths": {
5-
"@pages/*": ["pages/*"]
5+
"@pages/*": [
6+
"pages/*"
7+
]
68
},
79
"target": "es6",
8-
"lib": ["dom", "dom.iterable", "esnext"],
10+
"lib": [
11+
"dom",
12+
"dom.iterable",
13+
"esnext"
14+
],
915
"allowJs": true,
1016
"checkJs": true,
1117
"skipLibCheck": true,
@@ -17,9 +23,16 @@
1723
"moduleResolution": "node",
1824
"resolveJsonModule": true,
1925
"isolatedModules": true,
20-
"jsx": "react-jsx",
26+
"jsx": "preserve",
2127
"incremental": true
2228
},
23-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "__mocks__/styleMock.js"],
24-
"exclude": ["node_modules"]
29+
"include": [
30+
"next-env.d.ts",
31+
"**/*.ts",
32+
"**/*.tsx",
33+
"__mocks__/styleMock.js"
34+
],
35+
"exclude": [
36+
"node_modules"
37+
]
2538
}

app/tsconfig.ts-jest.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"jsx": "react-jsx"
5+
}
6+
}

0 commit comments

Comments
 (0)