fix(design-system): fix typist tests

This commit is contained in:
41666 2020-10-24 21:02:41 -04:00
parent b3c384421b
commit 4c3f5de0f6
7 changed files with 35 additions and 15 deletions

View file

@ -9,6 +9,7 @@ exports_files(
"tsconfig.json",
"jest.config.js",
"jest-reporter.js",
"hack/jestSetup.ts",
],
visibility = ["//visibility:public"],
)

View file

@ -19,7 +19,9 @@ DEFAULT_DEPS = [
"@npm//enzyme-to-json",
"@npm//react-dom",
"@npm//@types/react-dom",
"@npm//jest-react-hooks-shallow",
"//:tsconfig.json",
"//:hack/jestSetup.ts",
]
def _impl_jest_test(name, srcs, deps, jest_config, **kwargs):

4
hack/jestSetup.ts Normal file
View file

@ -0,0 +1,4 @@
import enableHooks from 'jest-react-hooks-shallow';
// pass an instance of jest to `enableHooks()`
enableHooks(jest);

View file

@ -5,7 +5,7 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'enzyme',
reporters: ['default', './jest-reporter'],
setupFilesAfterEnv: ['jest-enzyme', 'jest-styled-components'],
setupFilesAfterEnv: ['jest-enzyme', 'jest-styled-components', './hack/jestSetup.ts'],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/',
}),

View file

@ -72,6 +72,7 @@
"jest-cli": "^26.6.1",
"jest-environment-enzyme": "^7.1.2",
"jest-enzyme": "^7.1.2",
"jest-react-hooks-shallow": "^1.4.1",
"jest-styled-components": "^7.0.3",
"minimist": "^1.2.5",
"npm-run-all": "^4.1.5",

View file

@ -1,4 +1,4 @@
import { mount } from 'enzyme';
import { mount, shallow } from 'enzyme';
import * as React from 'react';
import { act } from 'react-dom/test-utils';
import { Typist } from './Typist';
@ -7,25 +7,21 @@ jest.useFakeTimers();
it('correctly cycles through provided lines', () => {
const lines = ['abcdef', 'ghijkl'];
act(() => {
let view = mount(<Typist charTimeout={100} resetTimeout={10000} lines={lines} />);
let view = shallow(<Typist charTimeout={100} resetTimeout={10000} lines={lines} />);
jest.advanceTimersByTime(100 * lines[0].length);
view = view.update();
expect(view.text()).toBe(lines[0]);
});
jest.advanceTimersByTime(100 * lines[0].length);
view = view.update();
expect(view.text()).toBe(lines[0]);
});
it('correctly cycles through provided characters in a line', () => {
const lines = ['abcdef'];
act(() => {
let view = mount(<Typist charTimeout={1} resetTimeout={100} lines={lines} />);
let view = shallow(<Typist charTimeout={1} resetTimeout={100} lines={lines} />);
Array(...lines[0]).forEach((_, idx) => {
view = view.update();
expect(view.text()).toBe(lines[0].slice(0, idx));
jest.advanceTimersByTime(1);
});
Array(...lines[0]).forEach((_, idx) => {
view = view.update();
expect(view.text()).toBe(lines[0].slice(0, idx));
jest.advanceTimersByTime(1);
});
});

View file

@ -8704,6 +8704,13 @@ jest-pnp-resolver@^1.2.2:
resolved "https://registry.yarnpkg.com/jest-pnp-resolver/-/jest-pnp-resolver-1.2.2.tgz#b704ac0ae028a89108a4d040b3f919dfddc8e33c"
integrity sha512-olV41bKSMm8BdnuMsewT4jqlZ8+3TCARAXjZGT9jcoSnrfUnRCqnMoF9XEeoWjbzObpqF9dRhHQj0Xb9QdF6/w==
jest-react-hooks-shallow@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/jest-react-hooks-shallow/-/jest-react-hooks-shallow-1.4.1.tgz#5a0082c7ef72c0434f55bd7ef4ff8fdbe4e0ab1d"
integrity sha512-el9oYNAp77WEUgVdBEjPMU+5koOFXfAhitlVShuBine/y2AVCL5nEF9kRDSu9iAo2mMocbwmeTEPyDsw/LAHvg==
dependencies:
react "^16.8.0"
jest-regex-util@^24.9.0:
version "24.9.0"
resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-24.9.0.tgz#c13fb3380bde22bf6575432c493ea8fe37965636"
@ -11577,6 +11584,15 @@ react-tooltip@^4.2.10:
prop-types "^15.7.2"
uuid "^7.0.3"
react@^16.8.0:
version "16.14.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.14.0.tgz#94d776ddd0aaa37da3eda8fc5b6b18a4c9a3114d"
integrity sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
react@^16.8.3:
version "16.13.1"
resolved "https://registry.yarnpkg.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"