diff --git a/package.json b/package.json index 7c92c13b..ae837125 100644 --- a/package.json +++ b/package.json @@ -50,12 +50,12 @@ }, "homepage": "https://github.com/reactjs/react-transition-group#readme", "jest": { - "testRegex": "-test\\.js", + "testRegex": "-test\\.[jt]sx?", "setupFiles": [ - "./test/setup.js" + "./test/setup.ts" ], "setupFilesAfterEnv": [ - "./test/setupAfterEnv.js" + "./test/setupAfterEnv.ts" ], "roots": [ "/test" @@ -83,6 +83,7 @@ "@storybook/addon-actions": "^6.3.4", "@storybook/react": "^6.3.4", "@testing-library/react": "alpha", + "@types/jest": "^27.5.0", "@types/prop-types": "^15.7.4", "@types/react": "^17.0.41", "@types/react-dom": "^17.0.14", diff --git a/src/utils/ChildMapping.ts b/src/utils/ChildMapping.ts index 98740760..c932cb98 100644 --- a/src/utils/ChildMapping.ts +++ b/src/utils/ChildMapping.ts @@ -43,11 +43,11 @@ export function getChildMapping( * in `next` in a reasonable order. */ export function mergeChildMappings( - prev: Record, - next: Record + prev_: Record | undefined, + next_: Record | undefined ) { - prev = prev || {}; - next = next || {}; + const prev = prev_ || {}; + const next = next_ || {}; function getValueForKey(key: string) { return key in next ? next[key] : prev[key]; diff --git a/test/.eslintrc.yml b/test/.eslintrc.yml index 3c0a3a9e..5d4473eb 100644 --- a/test/.eslintrc.yml +++ b/test/.eslintrc.yml @@ -1,6 +1,5 @@ env: jest: true - es6: true rules: no-require: off global-require: off diff --git a/test/ChildMapping-test.js b/test/ChildMapping-test.tsx similarity index 57% rename from test/ChildMapping-test.js rename to test/ChildMapping-test.tsx index 7afb2574..b3ea6de1 100644 --- a/test/ChildMapping-test.js +++ b/test/ChildMapping-test.tsx @@ -1,12 +1,7 @@ -let React; -let ChildMapping; +import React from 'react'; +import * as ChildMapping from '../src/utils/ChildMapping'; describe('ChildMapping', () => { - beforeEach(() => { - React = require('react'); - ChildMapping = require('../src/utils/ChildMapping'); - }); - it('should support getChildMapping', () => { let oneone =
; let onetwo =
; @@ -32,102 +27,102 @@ describe('ChildMapping', () => { it('should support mergeChildMappings for adding keys', () => { let prev = { - one: true, - two: true, + one: 'one', + two: 'two', }; let next = { - one: true, - two: true, - three: true, + one: 'one', + two: 'two', + three: 'three', }; expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ - one: true, - two: true, - three: true, + one: 'one', + two: 'two', + three: 'three', }); }); it('should support mergeChildMappings for removing keys', () => { let prev = { - one: true, - two: true, - three: true, + one: 'one', + two: 'two', + three: 'three', }; let next = { - one: true, - two: true, + one: 'one', + two: 'two', }; expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ - one: true, - two: true, - three: true, + one: 'one', + two: 'two', + three: 'three', }); }); it('should support mergeChildMappings for adding and removing', () => { let prev = { - one: true, - two: true, - three: true, + one: 'one', + two: 'two', + three: 'three', }; let next = { - one: true, - two: true, - four: true, + one: 'one', + two: 'two', + four: 'four', }; expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ - one: true, - two: true, - three: true, - four: true, + one: 'one', + two: 'two', + three: 'three', + four: 'four', }); }); it('should reconcile overlapping insertions and deletions', () => { let prev = { - one: true, - two: true, - four: true, - five: true, + one: 'one', + two: 'two', + four: 'four', + five: 'five', }; let next = { - one: true, - two: true, - three: true, - five: true, + one: 'one', + two: 'two', + three: 'three', + five: 'five', }; expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ - one: true, - two: true, - three: true, - four: true, - five: true, + one: 'one', + two: 'two', + three: 'three', + four: 'four', + five: 'five', }); }); it('should support mergeChildMappings with undefined input', () => { - let prev = { - one: true, - two: true, + const prev = { + one: 'one', + two: 'two', }; - let next; + const next = undefined; expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ - one: true, - two: true, + one: 'one', + two: 'two', }); - prev = undefined; + const prev2 = undefined; - next = { - three: true, - four: true, + const next2 = { + three: 'three', + four: 'four', }; - expect(ChildMapping.mergeChildMappings(prev, next)).toEqual({ - three: true, - four: true, + expect(ChildMapping.mergeChildMappings(prev2, next2)).toEqual({ + three: 'three', + four: 'four', }); }); }); diff --git a/test/SSR-test.js b/test/SSR-test.ts similarity index 93% rename from test/SSR-test.js rename to test/SSR-test.ts index 20c282de..8a8c1636 100644 --- a/test/SSR-test.js +++ b/test/SSR-test.ts @@ -7,5 +7,7 @@ import * as ReactTransitionGroup from '../src'; // eslint-disable-line no-unused-vars describe('SSR', () => { - it('should import react-transition-group in node env', () => {}); + it('should import react-transition-group in node env', () => { + /* noop */ + }); }); diff --git a/test/setup.js b/test/setup.ts similarity index 85% rename from test/setup.js rename to test/setup.ts index 85c00e4d..76af5f27 100644 --- a/test/setup.js +++ b/test/setup.ts @@ -1,3 +1,4 @@ +// @ts-ignore global.requestAnimationFrame = function (callback) { setTimeout(callback, 0); }; diff --git a/test/setupAfterEnv.js b/test/setupAfterEnv.ts similarity index 100% rename from test/setupAfterEnv.js rename to test/setupAfterEnv.ts diff --git a/test/utils.js b/test/utils.ts similarity index 52% rename from test/utils.js rename to test/utils.ts index e42aae60..1f582920 100644 --- a/test/utils.js +++ b/test/utils.ts @@ -1,13 +1,16 @@ -import { render as baseRender } from '@testing-library/react/pure'; +import { + render as baseRender, + RenderOptions, +} from '@testing-library/react/pure'; import React from 'react'; export * from '@testing-library/react'; -export function render(element, options) { +export function render(element: React.ReactElement, options?: RenderOptions) { const result = baseRender(element, options); return { ...result, - setProps(props) { + setProps(props: any) { result.rerender(React.cloneElement(element, props)); }, }; diff --git a/yarn.lock b/yarn.lock index e9105f1f..ef38be8b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3841,6 +3841,14 @@ "@types/istanbul-lib-coverage" "*" "@types/istanbul-lib-report" "*" +"@types/jest@^27.5.0": + version "27.5.0" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.5.0.tgz#e04ed1824ca6b1dd0438997ba60f99a7405d4c7b" + integrity sha512-9RBFx7r4k+msyj/arpfaa0WOOEcaAZNmN+j80KFbFCoSqCJGHTz7YMAMGQW9Xmqm5w6l5c25vbSjMwlikJi5+g== + dependencies: + jest-matcher-utils "^27.0.0" + pretty-format "^27.0.0" + "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.6", "@types/json-schema@^7.0.7": version "7.0.7" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad" @@ -7299,6 +7307,11 @@ diff-sequences@^25.2.6: resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-25.2.6.tgz#5f467c00edd35352b7bca46d7927d60e687a76dd" integrity sha512-Hq8o7+6GaZeoFjtpgvRBUknSXNeJiCx7V9Fr94ZMljNiCr9n9L8H8aJqgWOQiDDGdyn29fRNcDdRVJ5fdyihfg== +diff-sequences@^27.5.1: + version "27.5.1" + resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.5.1.tgz#eaecc0d327fd68c8d9672a1e64ab8dccb2ef5327" + integrity sha512-k1gCAXAsNgLwEL+Y8Wvl+M6oEFj5bgazfZULpS5CneoPPXRaCCW7dm+q21Ky2VEE5X+VeRDBVg1Pcvvsr4TtNQ== + diffie-hellman@^5.0.0: version "5.0.3" resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.3.tgz#40e8ee98f55a2149607146921c63e1ae5f3d2875" @@ -10662,6 +10675,16 @@ jest-diff@^25.1.0, jest-diff@^25.3.0: jest-get-type "^25.2.6" pretty-format "^25.3.0" +jest-diff@^27.5.1: + version "27.5.1" + resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.5.1.tgz#a07f5011ac9e6643cf8a95a462b7b1ecf6680def" + integrity sha512-m0NvkX55LDt9T4mctTEgnZk3fmEg3NRYutvMPWM/0iPnkFj2wIeF45O1718cMSOFO1vINkqmxqD8vE37uTEbqw== + dependencies: + chalk "^4.0.0" + diff-sequences "^27.5.1" + jest-get-type "^27.5.1" + pretty-format "^27.5.1" + jest-docblock@^25.3.0: version "25.3.0" resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-25.3.0.tgz#8b777a27e3477cd77a168c05290c471a575623ef" @@ -10709,6 +10732,11 @@ jest-get-type@^25.2.6: resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-25.2.6.tgz#0b0a32fab8908b44d508be81681487dbabb8d877" integrity sha512-DxjtyzOHjObRM+sM1knti6or+eOgcGU4xVSb2HNP1TqO4ahsT+rqZg+nyqHWJSvWgKC5cG3QjGFBqxLghiF/Ig== +jest-get-type@^27.5.1: + version "27.5.1" + resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-27.5.1.tgz#3cd613c507b0f7ace013df407a1c1cd578bcb4f1" + integrity sha512-2KY95ksYSaK7DMBWQn6dQz3kqAf3BB64y2udeG+hv4KfSOb9qwcYQstTJc1KCbsix+wLZWZYN8t7nwX3GOBLRw== + jest-haste-map@^25.3.0: version "25.3.0" resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-25.3.0.tgz#b7683031c9c9ddc0521d311564108b244b11e4c6" @@ -10769,6 +10797,16 @@ jest-matcher-utils@^25.3.0: jest-get-type "^25.2.6" pretty-format "^25.3.0" +jest-matcher-utils@^27.0.0: + version "27.5.1" + resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-27.5.1.tgz#9c0cdbda8245bc22d2331729d1091308b40cf8ab" + integrity sha512-z2uTx/T6LBaCoNWNFWwChLBKYxTMcGBRjAt+2SbP929/Fflb9aa5LGma654Rz8z9HLxsrUaYzxE9T/EFIL/PAw== + dependencies: + chalk "^4.0.0" + jest-diff "^27.5.1" + jest-get-type "^27.5.1" + pretty-format "^27.5.1" + jest-message-util@^25.3.0: version "25.3.0" resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-25.3.0.tgz#e3836826fe5ca538a337b87d9bd2648190867f85" @@ -14219,7 +14257,7 @@ pretty-format@^25.3.0: ansi-styles "^4.0.0" react-is "^16.12.0" -pretty-format@^27.0.2: +pretty-format@^27.0.0, pretty-format@^27.0.2, pretty-format@^27.5.1: version "27.5.1" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.1.tgz#2181879fdea51a7a5851fb39d920faa63f01d88e" integrity sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==