diff --git a/BUILD.bazel b/BUILD.bazel index 3ca720e..835d11d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -9,6 +9,7 @@ exports_files( "tsconfig.json", "jest.config.js", "jest-reporter.js", + "hack/jestSetup.ts", ], visibility = ["//visibility:public"], ) diff --git a/hack/bazel/js/jest.bzl b/hack/bazel/js/jest.bzl index e9f7072..ad70cae 100644 --- a/hack/bazel/js/jest.bzl +++ b/hack/bazel/js/jest.bzl @@ -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): diff --git a/hack/jestSetup.ts b/hack/jestSetup.ts new file mode 100644 index 0000000..a60a8bb --- /dev/null +++ b/hack/jestSetup.ts @@ -0,0 +1,4 @@ +import enableHooks from 'jest-react-hooks-shallow'; + +// pass an instance of jest to `enableHooks()` +enableHooks(jest); diff --git a/jest.config.js b/jest.config.js index 19b07cf..1fecd80 100644 --- a/jest.config.js +++ b/jest.config.js @@ -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: '/', }), diff --git a/package.json b/package.json index 01bf231..a18a43b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/design-system/atoms/typist/Typist.spec.tsx b/src/design-system/atoms/typist/Typist.spec.tsx index 3f2e409..efa7e66 100644 --- a/src/design-system/atoms/typist/Typist.spec.tsx +++ b/src/design-system/atoms/typist/Typist.spec.tsx @@ -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(); + let view = shallow(); - 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(); + let view = shallow(); - 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); }); }); diff --git a/yarn.lock b/yarn.lock index 74b01d2..d37a829 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"