Skip to content

Commit 2855a85

Browse files
committed
added partialComponentPropsMatcher to test components
1 parent e5e345b commit 2855a85

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

app/src/__testing-utils__/matchers.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
1+
import { when } from 'vitest-when'
22
import type { Matcher } from '@testing-library/react'
33

4-
54
// Match things like <p>Some <strong>nested</strong> text</p>
65
// Use with either string match: getByText(nestedTextMatcher("Some nested text"))
76
// or regexp: getByText(nestedTextMatcher(/Some nested text/))
@@ -21,3 +20,9 @@ export const nestedTextMatcher = (textMatch: string | RegExp): Matcher => (
2120

2221
return nodeHasText && childrenDontHaveText
2322
}
23+
24+
export const partialComponentPropsMatcher = (argsToMatch: unknown): any =>
25+
// @ts-expect-error(sa, 2021-08-03): when.allArgs not part of type definition yet for jest-when
26+
when.allArgs((args, equals) =>
27+
equals(args[0], expect.objectContaining(argsToMatch))
28+
)

app/src/organisms/ProtocolDetails/__tests__/ProtocolDetails.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { StaticRouter } from 'react-router-dom'
44
import { when } from 'vitest-when'
55
import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest'
66

7-
import { renderWithProviders } from '../../../__testing-utils__'
7+
import {
8+
partialComponentPropsMatcher,
9+
renderWithProviders,
10+
} from '../../../__testing-utils__'
811
import { i18n } from '../../../i18n'
912
import { ChooseRobotToRunProtocolSlideout } from '../../../organisms/ChooseRobotToRunProtocolSlideout'
1013
import {

0 commit comments

Comments
 (0)