Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Commit 61d95fb

Browse files
committed
add TSX component example
1 parent d1aece8 commit 61d95fb

File tree

9 files changed

+73
-10
lines changed

9 files changed

+73
-10
lines changed

babel.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module.exports = {
2-
presets: ['@babel/preset-env', '@babel/preset-react'],
2+
presets: [
3+
'@babel/preset-env',
4+
'@babel/preset-react',
5+
'@babel/preset-typescript',
6+
],
37
plugins: [
48
// allow lazy loaded components with dynamic "import(...)"
59
// https://babeljs.io/docs/en/babel-plugin-syntax-dynamic-import/

cypress.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"viewportHeight": 400,
44
"video": false,
55
"projectId": "z9dxah",
6-
"testFiles": "**/*spec.js",
6+
"testFiles": "**/*spec.{js,jsx,ts,tsx}",
77
"env": {
88
"cypress-react-unit-test": {
99
"react": "node_modules/react/umd/react.development.js",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import { mount } from 'cypress-react-unit-test'
3+
4+
const Button = ({ children, ...rest }) => {
5+
return <button {...rest}>{children}</button>
6+
}
7+
8+
describe('Component spec in typescript', () => {
9+
it('works', () => {
10+
mount(<Button>Button Label</Button>)
11+
cy.contains('button', 'Button Label').should('be.visible')
12+
})
13+
})

cypress/integration/ts-spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
describe('Cypress TypeScript', () => {
2+
it('works', () => {
3+
cy.wrap({ life: 42 })
4+
.its('life')
5+
.should('equal', 42)
6+
})
7+
})

cypress/plugins/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const webpackOptions = {
1313
module: {
1414
rules: [
1515
{
16-
test: /\.(js|jsx|mjs)$/,
16+
test: /\.(js|jsx|mjs|ts|tsx)$/,
1717
loader: 'babel-loader',
1818
options: babelConfig,
1919
},

cypress/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["./**/*.ts"],
4+
"compilerOptions": {
5+
"baseUrl": "../node_modules",
6+
"types": ["cypress"]
7+
}
8+
}

package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"@babel/plugin-transform-modules-commonjs": "7.7.5",
5151
"@babel/preset-env": "7.4.5",
5252
"@babel/preset-react": "7.0.0",
53+
"@babel/preset-typescript": "7.9.0",
5354
"@emotion/core": "10.0.22",
5455
"@material-ui/core": "4.9.5",
5556
"@material-ui/icons": "4.5.1",

webpack.config.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ const config = {
88
entry: APP_DIR + '/index.jsx',
99
output: {
1010
path: BUILD_DIR,
11-
filename: 'bundle.js'
11+
filename: 'bundle.js',
1212
},
1313
module: {
1414
rules: [
1515
{
16-
test: /\.(js|jsx|mjs)$/,
16+
test: /\.(js|jsx|mjs|ts|tsx)$/,
1717
loader: 'babel-loader',
1818
include: APP_DIR,
19-
options: babelConfig
19+
options: babelConfig,
2020
},
2121
{
2222
test: /\.css$/,
2323
exclude: [/node_modules/],
2424
include: APP_DIR,
25-
use: ['style-loader', 'css-loader']
26-
}
27-
]
28-
}
25+
use: ['style-loader', 'css-loader'],
26+
},
27+
],
28+
},
2929
}
3030

3131
module.exports = config

0 commit comments

Comments
 (0)