-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: follow mike request - replace data-testid for querySelector by …
…class on story_search_spec.js file
- Loading branch information
Showing
2 changed files
with
23 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,41 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import ReactDOM from 'react-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { StorySearch } from 'components/search/StorySearch'; | ||
|
||
describe('<StorySearch />', () => { | ||
beforeAll(() => { | ||
ReactDOM.createPortal = vi.fn(element => { | ||
return element; | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
const divPortal = global.document.createElement('div'); | ||
const divPortal = document.createElement('div'); | ||
divPortal.setAttribute('data-portal', 'search'); | ||
const body = global.document.querySelector('body'); | ||
const body = document.querySelector('body'); | ||
body.appendChild(divPortal); | ||
}); | ||
|
||
it('renders the component', () => { | ||
const { container } = render( | ||
<StorySearch projectId={1} search={vi.fn()} loading={false} /> | ||
); | ||
|
||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
describe('loading', () => { | ||
describe('when loading is true', () => { | ||
it('renders the spinner', () => { | ||
const { getByTestId } = render( | ||
const { container, debug } = render( | ||
<StorySearch projectId={1} search={vi.fn()} loading={true} /> | ||
); | ||
|
||
expect(getByTestId('story-search-spinner')).toBeInTheDocument(); | ||
expect( | ||
container.querySelector('.StorySearch__spinner') | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('renders the component', () => { | ||
const { container } = render( | ||
<StorySearch projectId={1} search={vi.fn()} loading={false} /> | ||
); | ||
|
||
expect(container).toBeInTheDocument(); | ||
}); | ||
}); |