Skip to content

Commit

Permalink
Merge branch 'main' into feat/byrole-disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Mar 8, 2023
2 parents eeebfc2 + fb069c9 commit 2209724
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@
"aria-query": "^5.0.0",
"chalk": "^4.1.0",
"dom-accessibility-api": "^0.5.9",
"lz-string": "^1.4.4",
"lz-string": "^1.5.0",
"pretty-format": "^27.0.2"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.6",
"@types/lz-string": "^1.3.34",
"jest-in-case": "^1.0.2",
"jest-snapshot-serializer-ansi": "^1.0.0",
"jest-watch-select-projects": "^2.0.0",
Expand Down
20 changes: 19 additions & 1 deletion src/__tests__/suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ beforeAll(() => {
configure({throwSuggestions: true})
})

beforeEach(() => {
// We're testing suggestions of find* queries but we're not interested in their time-related behavior.
// Real timers would make the test suite slower for no reason.
jest.useFakeTimers()
})

afterEach(() => {
configure({testIdAttribute: 'data-testid'})
jest.useRealTimers()
configure({testIdAttribute: 'data-testid', throwSuggestions: true})
console.warn.mockClear()
})

Expand Down Expand Up @@ -103,6 +110,17 @@ test('should not suggest when suggest is turned off for a query', () => {
).not.toThrowError()
})

test('should suggest when suggest is turned on for a specific query but disabled in config', () => {
configure({throwSuggestions: false})
renderIntoDocument(`
<button data-testid="foo">submit</button>
<button data-testid="foot">another</button>`)

expect(() => screen.getByTestId('foo', {suggest: true})).toThrowError(
"try this:\ngetByRole('button', { name: /submit/i })",
)
})

test('should suggest getByRole when used with getBy', () => {
renderIntoDocument(`<button data-testid="foo">submit</button>`)

Expand Down

0 comments on commit 2209724

Please sign in to comment.