From 08e5571cf335b00b49eede056bb686e1e829c45c Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Tue, 8 Feb 2022 15:24:14 +0100 Subject: [PATCH] feat: add testing-library expect matchers --- package.json | 1 + src/index.ts | 11 ++++++++--- src/typings.d.ts | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 src/typings.d.ts diff --git a/package.json b/package.json index 6797033..82bc503 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "dependencies": { "@storybook/expect": "storybook-jest", "@storybook/instrumenter": "6.4.0-rc.5", + "@testing-library/jest-dom": "^5.16.2", "jest-mock": "^27.3.0" }, "devDependencies": { diff --git a/src/index.ts b/src/index.ts index bc64c99..8264c9a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,15 @@ import { default as expectPatched } from '@storybook/expect'; import { instrument } from '@storybook/instrumenter'; +import * as matchers from '@testing-library/jest-dom/matchers'; import * as mock from 'jest-mock'; -export const { jest } = instrument({ jest: mock }); +const { jest } = instrument({ jest: mock }); -export const expect: typeof expectPatched = instrument( +const expect: typeof expectPatched = instrument( { expect: expectPatched }, - { intercept: (method, path) => path[0] !== 'expect' } + { intercept: (_method, path) => path[0] !== 'expect' } ).expect; + +expect.extend(matchers); + +export { expect, jest }; diff --git a/src/typings.d.ts b/src/typings.d.ts new file mode 100644 index 0000000..f807926 --- /dev/null +++ b/src/typings.d.ts @@ -0,0 +1 @@ +declare module '@testing-library/jest-dom/matchers';