-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: usage of hook on testinho and update of tests
refactor #30
- Loading branch information
1 parent
e28c245
commit 9117aa1
Showing
5 changed files
with
48 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
import { render } from '@testing-library/react'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
|
||
import Testinho from './Testinho'; | ||
|
||
test('renders Testinho with default name', () => { | ||
const { getByText } = render(<Testinho />); | ||
const linkElement = getByText(/Hello, World!/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
}); | ||
describe('testinhoComponent', () => { | ||
describe('when no props is passed', () => { | ||
it('render with de default value', () => { | ||
const { getByRole } = render(<Testinho />); | ||
const linkElement = getByRole('heading', { level: 1 }); | ||
expect(linkElement.textContent).toBe('Hello, World!'); | ||
}); | ||
}); | ||
|
||
describe('when props is passed', () => { | ||
it('renders with the provided prop', () => { | ||
const { getByRole } = render(<Testinho name="React" />); | ||
const linkElement = getByRole('heading', { level: 1 }); | ||
expect(linkElement.textContent).toBe('Hello, React!'); | ||
}); | ||
}); | ||
|
||
describe('when interact with the posts button', () => { | ||
it('sucessfully change value of posts', () => { | ||
const LABEL = 'Number of posts:'; | ||
const { getByRole } = render(<Testinho />); | ||
|
||
const postsLabel = screen.getByText(`${LABEL} 0`); | ||
expect(postsLabel.textContent).toBe(`${LABEL} 0`); | ||
|
||
const increaseButton = getByRole('button'); | ||
|
||
fireEvent.click(increaseButton); | ||
|
||
test('renders Testinho with provided name', () => { | ||
const { getByText } = render(<Testinho name="React" />); | ||
const linkElement = getByText(/Hello, React!/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
expect(postsLabel.textContent).toBe(`${LABEL} 1`); | ||
}); | ||
}); | ||
}); |
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
File renamed without changes.
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