Skip to content
This repository was archived by the owner on May 2, 2023. It is now read-only.

Commit 9cd5468

Browse files
committed
Add simple test for prepareStory
Note that without extending the top-level tsconfig.json from tsconfig.base.json, the right compiler options weren't being applied for the tests, even though they are inherited by the individual project tsconfig.jsons (react and esModuleInterop). Extending the top level one from the base solves the issue, but feels wrong... I would've thought that because each project gets the right config, the tests should've worked right. Also building works fine, but it is Jest or ts-jest causing the issue. Pretty sure this is related to - kulshekhar/ts-jest#1648 - microsoft/TypeScript#37239
1 parent fe55d1f commit 9cd5468

File tree

6 files changed

+138
-4
lines changed

6 files changed

+138
-4
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ module.exports = {
1212
'plugin:import/warnings',
1313
'plugin:import/typescript',
1414
'plugin:prettier/recommended',
15+
'plugin:testing-library/recommended',
1516
],
1617
parser: '@typescript-eslint/parser',
1718
parserOptions: {
1819
ecmaVersion: 12,
1920
sourceType: 'module',
2021
},
2122
ignorePatterns: ['storybook-static/', 'build/'],
22-
plugins: ['@typescript-eslint', 'import', 'jest'],
23+
plugins: ['@typescript-eslint', 'testing-library', 'import', 'jest'],
2324
rules: {
2425
'@typescript-eslint/explicit-module-boundary-types': 'off',
2526
'@typescript-eslint/no-empty-function': 'off',

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
"@babel/core": "^7.12.3",
2424
"@octokit/core": "^3.2.1",
2525
"@storybook/react": "^6.0.28",
26+
"@testing-library/react": "^11.1.2",
2627
"@types/jest": "^26.0.15",
28+
"@types/react": "^16.9.56",
2729
"@typescript-eslint/eslint-plugin": "^4.8.1",
2830
"@typescript-eslint/parser": "^4.8.1",
2931
"eslint": "^7.12.1",
3032
"eslint-config-prettier": "^6.15.0",
3133
"eslint-plugin-import": "^2.22.1",
3234
"eslint-plugin-jest": "^24.1.3",
3335
"eslint-plugin-prettier": "^3.1.4",
36+
"eslint-plugin-testing-library": "^3.10.0",
3437
"jest": "^26.6.3",
3538
"lerna": "^3.22.1",
3639
"prettier": "^2.1.2",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
import { render, screen } from '@testing-library/react';
5+
import React from 'react';
6+
import prepareStory from '../prepareStory';
7+
8+
test('no args', () => {
9+
const Story = () => <button>brew</button>;
10+
11+
render(prepareStory(Story));
12+
expect(screen.getByRole('button', { name: 'brew' })).toBeTruthy();
13+
});
14+
15+
test('args', () => {
16+
type Args = { children: React.ReactNode };
17+
const Story = (args: Args) => <button {...args} />;
18+
Story.args = { children: 'hiya' };
19+
20+
render(prepareStory(Story));
21+
expect(screen.getByRole('button', { name: 'hiya' })).toBeTruthy();
22+
});
23+
24+
test('args and overrides', () => {
25+
type Args = { children: React.ReactNode };
26+
const Story = (args: Args) => <button {...args} />;
27+
Story.args = { children: 'hiya' };
28+
29+
render(prepareStory(Story, { children: 'byeya' }));
30+
expect(screen.getByRole('button', { name: 'byeya' })).toBeTruthy();
31+
});

tsconfig.base.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"esModuleInterop": true,
88
"forceConsistentCasingInFileNames": true,
99
"isolatedModules": true,
10+
"jsx": "react",
1011
"lib": ["es2019"],
1112
"module": "commonjs",
1213
"target": "es5",

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"extends": "./tsconfig.base.json",
23
"files": [],
34
"references": [
45
{

yarn.lock

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,15 @@
986986
pirates "^4.0.0"
987987
source-map-support "^0.5.16"
988988

989-
"@babel/runtime@^7.1.2", "@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.0", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
989+
"@babel/runtime-corejs3@^7.10.2":
990+
version "7.12.5"
991+
resolved "https://registry.yarnpkg.com/@babel/runtime-corejs3/-/runtime-corejs3-7.12.5.tgz#ffee91da0eb4c6dae080774e94ba606368e414f4"
992+
integrity sha512-roGr54CsTmNPPzZoCP1AmDXuBoNao7tnSA83TXTwt+UK5QVyh1DIJnrgYRPWKCF2flqZQXwa7Yr8v7VmLzF0YQ==
993+
dependencies:
994+
core-js-pure "^3.0.0"
995+
regenerator-runtime "^0.13.4"
996+
997+
"@babel/runtime@^7.1.2", "@babel/runtime@^7.10.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.5", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.0", "@babel/runtime@^7.5.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.7.6", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
990998
version "7.12.5"
991999
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e"
9921000
integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==
@@ -2794,11 +2802,38 @@
27942802
"@svgr/plugin-svgo" "^5.5.0"
27952803
loader-utils "^2.0.0"
27962804

2805+
"@testing-library/dom@^7.26.6":
2806+
version "7.26.7"
2807+
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-7.26.7.tgz#b9008b21524288fb09f7bc20bf366a3aa1f0ce72"
2808+
integrity sha512-Ykb+W02Q5lAAuwwANq/LCxMqrLKF7S+udJ0tFDwyuHyr84kQ2YKeYdIl5B3HnLKSWK4mGqA+Xe7dbU25DXhlkQ==
2809+
dependencies:
2810+
"@babel/code-frame" "^7.10.4"
2811+
"@babel/runtime" "^7.12.5"
2812+
"@types/aria-query" "^4.2.0"
2813+
aria-query "^4.2.2"
2814+
chalk "^4.1.0"
2815+
dom-accessibility-api "^0.5.4"
2816+
lz-string "^1.4.4"
2817+
pretty-format "^26.6.2"
2818+
2819+
"@testing-library/react@^11.1.2":
2820+
version "11.1.2"
2821+
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-11.1.2.tgz#089b06d3828e76fc1ff0092dd69c7b59c454c998"
2822+
integrity sha512-foL0/Mo68M51DdgFwEsO2SDEkUpocuEYidOTcJACGEcoakZDINuERYwVdd6T5e3pPE+BZyGwwURaXcrX1v9RbQ==
2823+
dependencies:
2824+
"@babel/runtime" "^7.12.1"
2825+
"@testing-library/dom" "^7.26.6"
2826+
27972827
"@types/anymatch@*":
27982828
version "1.3.1"
27992829
resolved "https://registry.yarnpkg.com/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a"
28002830
integrity sha512-/+CRPXpBDpo2RK9C68N3b2cOvO0Cf5B9aPijHsoDQTHivnGSObdOF2BRQOYjojWTDy6nQvMjmqRXIxH55VjxxA==
28012831

2832+
"@types/aria-query@^4.2.0":
2833+
version "4.2.0"
2834+
resolved "https://registry.yarnpkg.com/@types/aria-query/-/aria-query-4.2.0.tgz#14264692a9d6e2fa4db3df5e56e94b5e25647ac0"
2835+
integrity sha512-iIgQNzCm0v7QMhhe4Jjn9uRh+I6GoPmt03CbEtwx3ao8/EfoQcmgtqH4vQ5Db/lxiIGaWDv6nwvunuh0RyX0+A==
2836+
28022837
"@types/babel__core@^7.0.0", "@types/babel__core@^7.1.7":
28032838
version "7.1.12"
28042839
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.12.tgz#4d8e9e51eb265552a7e4f1ff2219ab6133bdfb2d"
@@ -3039,7 +3074,7 @@
30393074
dependencies:
30403075
"@types/react" "*"
30413076

3042-
"@types/react@*":
3077+
"@types/react@*", "@types/react@^16.9.56":
30433078
version "16.9.56"
30443079
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.56.tgz#ea25847b53c5bec064933095fc366b1462e2adf0"
30453080
integrity sha512-gIkl4J44G/qxbuC6r2Xh+D3CGZpJ+NdWTItAPmZbR5mUS+JQ8Zvzpl0ea5qT/ZT3ZNTUcDKUVqV3xBE8wv/DyQ==
@@ -3139,6 +3174,17 @@
31393174
eslint-scope "^5.0.0"
31403175
eslint-utils "^2.0.0"
31413176

3177+
"@typescript-eslint/experimental-utils@^3.10.1":
3178+
version "3.10.1"
3179+
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.10.1.tgz#e179ffc81a80ebcae2ea04e0332f8b251345a686"
3180+
integrity sha512-DewqIgscDzmAfd5nOGe4zm6Bl7PKtMG2Ad0KG8CUZAHlXfAKTF9Ol5PXhiMh39yRL2ChRH1cuuUGOcVyyrhQIw==
3181+
dependencies:
3182+
"@types/json-schema" "^7.0.3"
3183+
"@typescript-eslint/types" "3.10.1"
3184+
"@typescript-eslint/typescript-estree" "3.10.1"
3185+
eslint-scope "^5.0.0"
3186+
eslint-utils "^2.0.0"
3187+
31423188
"@typescript-eslint/parser@^4.8.1":
31433189
version "4.8.1"
31443190
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.8.1.tgz#4fe2fbdbb67485bafc4320b3ae91e34efe1219d1"
@@ -3157,11 +3203,30 @@
31573203
"@typescript-eslint/types" "4.8.1"
31583204
"@typescript-eslint/visitor-keys" "4.8.1"
31593205

3206+
"@typescript-eslint/types@3.10.1":
3207+
version "3.10.1"
3208+
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-3.10.1.tgz#1d7463fa7c32d8a23ab508a803ca2fe26e758727"
3209+
integrity sha512-+3+FCUJIahE9q0lDi1WleYzjCwJs5hIsbugIgnbB+dSCYUxl8L6PwmsyOPFZde2hc1DlTo/xnkOgiTLSyAbHiQ==
3210+
31603211
"@typescript-eslint/types@4.8.1":
31613212
version "4.8.1"
31623213
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.8.1.tgz#23829c73c5fc6f4fcd5346a7780b274f72fee222"
31633214
integrity sha512-ave2a18x2Y25q5K05K/U3JQIe2Av4+TNi/2YuzyaXLAsDx6UZkz1boZ7nR/N6Wwae2PpudTZmHFXqu7faXfHmA==
31643215

3216+
"@typescript-eslint/typescript-estree@3.10.1":
3217+
version "3.10.1"
3218+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.10.1.tgz#fd0061cc38add4fad45136d654408569f365b853"
3219+
integrity sha512-QbcXOuq6WYvnB3XPsZpIwztBoquEYLXh2MtwVU+kO8jgYCiv4G5xrSP/1wg4tkvrEE+esZVquIPX/dxPlePk1w==
3220+
dependencies:
3221+
"@typescript-eslint/types" "3.10.1"
3222+
"@typescript-eslint/visitor-keys" "3.10.1"
3223+
debug "^4.1.1"
3224+
glob "^7.1.6"
3225+
is-glob "^4.0.1"
3226+
lodash "^4.17.15"
3227+
semver "^7.3.2"
3228+
tsutils "^3.17.1"
3229+
31653230
"@typescript-eslint/typescript-estree@4.8.1":
31663231
version "4.8.1"
31673232
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.8.1.tgz#7307e3f2c9e95df7daa8dc0a34b8c43b7ec0dd32"
@@ -3176,6 +3241,13 @@
31763241
semver "^7.3.2"
31773242
tsutils "^3.17.1"
31783243

3244+
"@typescript-eslint/visitor-keys@3.10.1":
3245+
version "3.10.1"
3246+
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-3.10.1.tgz#cd4274773e3eb63b2e870ac602274487ecd1e931"
3247+
integrity sha512-9JgC82AaQeglebjZMgYR5wgmfUdUc+EitGUUMW8u2nDckaeimzW+VsoLV6FoimPv2id3VQzfjwBxEMVz08ameQ==
3248+
dependencies:
3249+
eslint-visitor-keys "^1.1.0"
3250+
31793251
"@typescript-eslint/visitor-keys@4.8.1":
31803252
version "4.8.1"
31813253
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.8.1.tgz#794f68ee292d1b2e3aa9690ebedfcb3a8c90e3c3"
@@ -3622,6 +3694,14 @@ argparse@^1.0.7:
36223694
dependencies:
36233695
sprintf-js "~1.0.2"
36243696

3697+
aria-query@^4.2.2:
3698+
version "4.2.2"
3699+
resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-4.2.2.tgz#0d2ca6c9aceb56b8977e9fed6aed7e15bbd2f83b"
3700+
integrity sha512-o/HelwhuKpTj/frsOsbNLNgnNGVIFsVP/SW2BSF14gVl7kAfMOJ6/8wUAUvG1R1NHKrfG+2sHZTu0yauT1qBrA==
3701+
dependencies:
3702+
"@babel/runtime" "^7.10.2"
3703+
"@babel/runtime-corejs3" "^7.10.2"
3704+
36253705
arr-diff@^4.0.0:
36263706
version "4.0.0"
36273707
resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-4.0.0.tgz#d6461074febfec71e7e15235761a329a5dc7c520"
@@ -5196,7 +5276,7 @@ core-js-compat@^3.6.2:
51965276
browserslist "^4.14.6"
51975277
semver "7.0.0"
51985278

5199-
core-js-pure@^3.0.1:
5279+
core-js-pure@^3.0.0, core-js-pure@^3.0.1:
52005280
version "3.7.0"
52015281
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.7.0.tgz#28a57c861d5698e053f0ff36905f7a3301b4191e"
52025282
integrity sha512-EZD2ckZysv8MMt4J6HSvS9K2GdtlZtdBncKAmF9lr2n0c9dJUaUN88PSTjvgwCgQPWKTkERXITgS6JJRAnljtg==
@@ -5732,6 +5812,11 @@ doctrine@^3.0.0:
57325812
dependencies:
57335813
esutils "^2.0.2"
57345814

5815+
dom-accessibility-api@^0.5.4:
5816+
version "0.5.4"
5817+
resolved "https://registry.yarnpkg.com/dom-accessibility-api/-/dom-accessibility-api-0.5.4.tgz#b06d059cdd4a4ad9a79275f9d414a5c126241166"
5818+
integrity sha512-TvrjBckDy2c6v6RLxPv5QXOnU+SmF9nBII5621Ve5fu6Z/BDrENurBEvlC1f44lKEUVqOpK4w9E5Idc5/EgkLQ==
5819+
57355820
dom-converter@^0.2:
57365821
version "0.2.0"
57375822
resolved "https://registry.yarnpkg.com/dom-converter/-/dom-converter-0.2.0.tgz#6721a9daee2e293682955b6afe416771627bb768"
@@ -6224,6 +6309,13 @@ eslint-plugin-prettier@^3.1.4:
62246309
dependencies:
62256310
prettier-linter-helpers "^1.0.0"
62266311

6312+
eslint-plugin-testing-library@^3.10.0:
6313+
version "3.10.0"
6314+
resolved "https://registry.yarnpkg.com/eslint-plugin-testing-library/-/eslint-plugin-testing-library-3.10.0.tgz#8c3c9c475bb4e5794446920d363403ae5bcf7f1c"
6315+
integrity sha512-zqITQ9qS9tdTG5hY+JnY4k3osolg4sGMD9gTnJr0L1xKB8CvPXXts7tp331ZjQ6qL37kRgH0288/XtsG+bcsxQ==
6316+
dependencies:
6317+
"@typescript-eslint/experimental-utils" "^3.10.1"
6318+
62276319
eslint-scope@^4.0.3:
62286320
version "4.0.3"
62296321
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.3.tgz#ca03833310f6889a3264781aa82e63eb9cfe7848"
@@ -9136,6 +9228,11 @@ lru-cache@^6.0.0:
91369228
dependencies:
91379229
yallist "^4.0.0"
91389230

9231+
lz-string@^1.4.4:
9232+
version "1.4.4"
9233+
resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.4.4.tgz#c0d8eaf36059f705796e1e344811cf4c498d3a26"
9234+
integrity sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY=
9235+
91399236
macos-release@^2.2.0:
91409237
version "2.4.1"
91419238
resolved "https://registry.yarnpkg.com/macos-release/-/macos-release-2.4.1.tgz#64033d0ec6a5e6375155a74b1a1eba8e509820ac"

0 commit comments

Comments
 (0)