Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add ts-jest example #10343

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions examples/typescript-ts-jest/CheckboxWithLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.

import * as React from 'react';

interface CheckboxWithLabelProps {
labelRef: React.LegacyRef<HTMLLabelElement>;
inputRef: React.LegacyRef<HTMLInputElement>;
labelOff: string;
labelOn: string;
}

interface CheckboxWithLabelState {
isChecked: boolean;
}

class CheckboxWithLabel extends React.Component<
CheckboxWithLabelProps,
CheckboxWithLabelState
> {
constructor(props: CheckboxWithLabelProps) {
super(props);
this.state = {isChecked: false};
}

render() {
return (
<label ref={this.props.labelRef}>
<input
ref={this.props.inputRef}
type="checkbox"
checked={this.state.isChecked}
onChange={() =>
this.setState(current => ({isChecked: !current.isChecked}))
}
/>
{this.state.isChecked ? this.props.labelOn : this.props.labelOff}
</label>
);
}
}

export default CheckboxWithLabel;
29 changes: 29 additions & 0 deletions examples/typescript-ts-jest/__tests__/CheckboxWithLabel-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.

import * as React from 'react';
import * as TestUtils from 'react-dom/test-utils';
import CheckboxWithLabel from '../CheckboxWithLabel';

it('CheckboxWithLabel changes the text after click', () => {
const checkboxLabelRef: React.RefObject<HTMLLabelElement> = React.createRef();
const checkboxInputRef: React.RefObject<HTMLInputElement> = React.createRef();
// Render a checkbox with label in the document
TestUtils.renderIntoDocument(
<CheckboxWithLabel
labelRef={checkboxLabelRef}
inputRef={checkboxInputRef}
labelOn="On"
labelOff="Off"
/>,
);

const labelNode = checkboxLabelRef.current;
const inputNode = checkboxInputRef.current;

// Verify that it's Off by default
expect(labelNode.textContent).toEqual('Off');

// Simulate a click and verify that it is now On
TestUtils.Simulate.change(inputNode);
expect(labelNode.textContent).toEqual('On');
});
21 changes: 21 additions & 0 deletions examples/typescript-ts-jest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"private": true,
"version": "0.0.0",
"name": "example-typescript-with-ts-jest",
"dependencies": {
"react": "*",
"react-dom": "*"
},
"devDependencies": {
"@types/jest": "*",
"jest": "*",
"ts-jest": "*",
"typescript": "*"
},
"scripts": {
"test": "jest"
},
"jest": {
"preset": "ts-jest"
}
}
6 changes: 6 additions & 0 deletions examples/typescript-ts-jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"module": "commonjs",
"jsx": "react"
}
}
5 changes: 1 addition & 4 deletions jest.config.ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ module.exports = {
'jest-junit',
{outputDirectory: 'reports/junit', outputName: 'js-test-results.xml'},
],
[
'jest-silent-reporter',
{showPaths: true, showWarnings: true, useDots: true},
],
'default',
],
};
120 changes: 86 additions & 34 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5045,6 +5045,15 @@ __metadata:
languageName: node
linkType: hard

"bs-logger@npm:0.x":
version: 0.2.6
resolution: "bs-logger@npm:0.2.6"
dependencies:
fast-json-stable-stringify: 2.x
checksum: f5f2f1315d6ceac655c3945d149086a5f5a90b3c908780757e12e938aad0125a7aa563cae2f7153ccf43443adb1b88a44960a61063903c3973e1dfdda6fc2d8c
languageName: node
linkType: hard

"bser@npm:2.1.1":
version: 2.1.1
resolution: "bser@npm:2.1.1"
Expand Down Expand Up @@ -5099,7 +5108,7 @@ __metadata:
languageName: node
linkType: hard

"buffer-from@npm:^1.0.0":
"buffer-from@npm:1.x, buffer-from@npm:^1.0.0":
version: 1.1.1
resolution: "buffer-from@npm:1.1.1"
checksum: 540ceb79c4f5bfcadaabbc18324fa84c50dc52905084be7c03596a339cf5a88513bee6831ce9b36ddd046fab09257a7c80686e129d0559a0cfd141da196ad956
Expand Down Expand Up @@ -8090,6 +8099,19 @@ __metadata:
languageName: unknown
linkType: soft

"example-typescript-with-ts-jest@workspace:examples/typescript-ts-jest":
version: 0.0.0-use.local
resolution: "example-typescript-with-ts-jest@workspace:examples/typescript-ts-jest"
dependencies:
"@types/jest": "*"
jest: "*"
react: "*"
react-dom: "*"
ts-jest: "*"
typescript: "*"
languageName: unknown
linkType: soft

"example-typescript@workspace:examples/typescript":
version: 0.0.0-use.local
resolution: "example-typescript@workspace:examples/typescript"
Expand Down Expand Up @@ -8439,7 +8461,7 @@ __metadata:
languageName: node
linkType: hard

"fast-json-stable-stringify@npm:^2.0.0":
"fast-json-stable-stringify@npm:2.x, fast-json-stable-stringify@npm:^2.0.0":
version: 2.1.0
resolution: "fast-json-stable-stringify@npm:2.1.0"
checksum: 7df3fabfe445d65953b2d9d9d3958bd895438b215a40fb87dae8b2165c5169a897785eb5d51e6cf0eb03523af756e3d82ea01083f6ac6341fe16db532fee3016
Expand Down Expand Up @@ -11593,7 +11615,7 @@ fsevents@^1.2.7:
languageName: unknown
linkType: soft

"jest-util@^26.2.0, jest-util@workspace:packages/jest-util":
"jest-util@26.x, jest-util@^26.2.0, jest-util@workspace:packages/jest-util":
version: 0.0.0-use.local
resolution: "jest-util@workspace:packages/jest-util"
dependencies:
Expand Down Expand Up @@ -11929,25 +11951,25 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"json5@npm:^1.0.1":
version: 1.0.1
resolution: "json5@npm:1.0.1"
"json5@npm:2.x, json5@npm:^2.1.2":
version: 2.1.3
resolution: "json5@npm:2.1.3"
dependencies:
minimist: ^1.2.0
minimist: ^1.2.5
bin:
json5: lib/cli.js
checksum: df41624f9f40bfacc546f779eef6d161a3312fbb6ec1dbd69f8c4388e9807af653b753371ab19b6d2bab22af2ca7dde62fe03c791596acf76915e1fc4ee6fd88
checksum: 957e4937106cf59975aa0281e68911534d65c8a25be5b4d3559aa55eba351ccab516a943a60ba33e461e4b8af749939986e311de910cbcfd197410b57d971741
languageName: node
linkType: hard

"json5@npm:^2.1.2":
version: 2.1.3
resolution: "json5@npm:2.1.3"
"json5@npm:^1.0.1":
version: 1.0.1
resolution: "json5@npm:1.0.1"
dependencies:
minimist: ^1.2.5
minimist: ^1.2.0
bin:
json5: lib/cli.js
checksum: 957e4937106cf59975aa0281e68911534d65c8a25be5b4d3559aa55eba351ccab516a943a60ba33e461e4b8af749939986e311de910cbcfd197410b57d971741
checksum: df41624f9f40bfacc546f779eef6d161a3312fbb6ec1dbd69f8c4388e9807af653b753371ab19b6d2bab22af2ca7dde62fe03c791596acf76915e1fc4ee6fd88
languageName: node
linkType: hard

Expand Down Expand Up @@ -12380,7 +12402,7 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"lodash.memoize@npm:^4.1.2":
"lodash.memoize@npm:4.x, lodash.memoize@npm:^4.1.2":
version: 4.1.2
resolution: "lodash.memoize@npm:4.1.2"
checksum: 080c1095b7795b293a06078737550dc0c8138192cadbafb4e4b1303357d367ac589a1a570fad8de154175b008ca7b2b48d6a7f1755a143e13b764e20a7104080
Expand Down Expand Up @@ -12625,6 +12647,13 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"make-error@npm:1.x":
version: 1.3.6
resolution: "make-error@npm:1.3.6"
checksum: 2c780bab8409b865e8ee86697c599a2bf2765ec64d21eb67ccda27050e039f983feacad05a0d43aba3c966ea03d305d2612e94fec45474bcbc61181f57c5bb88
languageName: node
linkType: hard

"make-fetch-happen@npm:^5.0.0":
version: 5.0.2
resolution: "make-fetch-happen@npm:5.0.2"
Expand Down Expand Up @@ -13339,7 +13368,7 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"mkdirp@npm:*, mkdirp@npm:^1.0.3, mkdirp@npm:^1.0.4":
"mkdirp@npm:*, mkdirp@npm:1.x, mkdirp@npm:^1.0.3, mkdirp@npm:^1.0.4":
version: 1.0.4
resolution: "mkdirp@npm:1.0.4"
bin:
Expand Down Expand Up @@ -16751,6 +16780,15 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"semver@npm:7.x, semver@npm:^7.2.1, semver@npm:^7.3.2":
version: 7.3.2
resolution: "semver@npm:7.3.2"
bin:
semver: bin/semver.js
checksum: bceb46d396d039afb5be2b2860bce1b0a43ecbadc72dde7ebe9c56dd9035ca50d9b8e086208ff9bbe53773ebde0bcfc6fc0842d7358398bca7054bb9ced801e3
languageName: node
linkType: hard

"semver@npm:^6.0.0, semver@npm:^6.1.2, semver@npm:^6.2.0, semver@npm:^6.3.0":
version: 6.3.0
resolution: "semver@npm:6.3.0"
Expand All @@ -16760,15 +16798,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"semver@npm:^7.2.1, semver@npm:^7.3.2":
version: 7.3.2
resolution: "semver@npm:7.3.2"
bin:
semver: bin/semver.js
checksum: bceb46d396d039afb5be2b2860bce1b0a43ecbadc72dde7ebe9c56dd9035ca50d9b8e086208ff9bbe53773ebde0bcfc6fc0842d7358398bca7054bb9ced801e3
languageName: node
linkType: hard

"send@npm:0.17.1":
version: 0.17.1
resolution: "send@npm:0.17.1"
Expand Down Expand Up @@ -18315,6 +18344,29 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"ts-jest@npm:*":
version: 26.1.4
resolution: "ts-jest@npm:26.1.4"
dependencies:
bs-logger: 0.x
buffer-from: 1.x
fast-json-stable-stringify: 2.x
jest-util: 26.x
json5: 2.x
lodash.memoize: 4.x
make-error: 1.x
mkdirp: 1.x
semver: 7.x
yargs-parser: 18.x
peerDependencies:
jest: ">=26 <27"
typescript: ">=3.8 <4.0"
bin:
ts-jest: cli.js
checksum: e69d84f07e4c2fe8ccb7556c00ff5f72fa41c18cb0ba38544265a62702556309d1cea59cef6297a2deef8042b45dcbd8b8493e3f8449372db563f2c4cef5b1d6
languageName: node
linkType: hard

"tslib@npm:^1.10.0, tslib@npm:^1.8.1, tslib@npm:^1.9.0, tslib@npm:^1.9.3":
version: 1.11.1
resolution: "tslib@npm:1.11.1"
Expand Down Expand Up @@ -19472,6 +19524,16 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"yargs-parser@npm:18.x, yargs-parser@npm:^18.1.1":
version: 18.1.3
resolution: "yargs-parser@npm:18.1.3"
dependencies:
camelcase: ^5.0.0
decamelize: ^1.2.0
checksum: 33871721679053cc38165afc6356c06c3e820459589b5db78f315886105070eb90cbb583cd6515fa4231937d60c80262ca2b7c486d5942576802446318a39597
languageName: node
linkType: hard

"yargs-parser@npm:^10.0.0":
version: 10.1.0
resolution: "yargs-parser@npm:10.1.0"
Expand Down Expand Up @@ -19501,16 +19563,6 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"yargs-parser@npm:^18.1.1":
version: 18.1.3
resolution: "yargs-parser@npm:18.1.3"
dependencies:
camelcase: ^5.0.0
decamelize: ^1.2.0
checksum: 33871721679053cc38165afc6356c06c3e820459589b5db78f315886105070eb90cbb583cd6515fa4231937d60c80262ca2b7c486d5942576802446318a39597
languageName: node
linkType: hard

"yargs@npm:^12.0.5":
version: 12.0.5
resolution: "yargs@npm:12.0.5"
Expand Down