Skip to content

Commit

Permalink
added partialComponentPropsMatcher to test components
Browse files Browse the repository at this point in the history
  • Loading branch information
koji committed Feb 28, 2024
1 parent e5e345b commit 2855a85
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions app/src/__testing-utils__/matchers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

import { when } from 'vitest-when'
import type { Matcher } from '@testing-library/react'


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

return nodeHasText && childrenDontHaveText
}

export const partialComponentPropsMatcher = (argsToMatch: unknown): any =>
// @ts-expect-error(sa, 2021-08-03): when.allArgs not part of type definition yet for jest-when
when.allArgs((args, equals) =>
equals(args[0], expect.objectContaining(argsToMatch))
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { StaticRouter } from 'react-router-dom'
import { when } from 'vitest-when'
import { describe, it, beforeEach, vi, expect, afterEach } from 'vitest'

import { renderWithProviders } from '../../../__testing-utils__'
import {
partialComponentPropsMatcher,
renderWithProviders,
} from '../../../__testing-utils__'
import { i18n } from '../../../i18n'
import { ChooseRobotToRunProtocolSlideout } from '../../../organisms/ChooseRobotToRunProtocolSlideout'
import {
Expand Down

0 comments on commit 2855a85

Please sign in to comment.