-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: follow testing-library best practices
- Loading branch information
1 parent
d669e23
commit 6ba7888
Showing
15 changed files
with
519 additions
and
337 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,4 +1,5 @@ | ||
module.exports = { | ||
plugins: ['@ant-design-vue/babel-plugin-jsx'], | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
|
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
trailingComma: 'es5', | ||
semi: false, | ||
singleQuote: true, | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Box } from '.' | ||
import { renderJsx, getByText } from '../../test/utils' | ||
|
||
describe('Box', () => { | ||
it('renders correctly', () => { | ||
renderJsx(<Box>foo</Box>) | ||
expect(getByText('foo')).toMatchInlineSnapshot(` | ||
<div> | ||
foo | ||
</div> | ||
`) | ||
}) | ||
|
||
it('renders passed attributes', () => { | ||
renderJsx( | ||
<Box tabIndex="0" class="bar" unicorn> | ||
foo | ||
</Box> | ||
) | ||
expect(getByText('foo')).toMatchInlineSnapshot(` | ||
<div | ||
class="bar" | ||
tabindex="0" | ||
unicorn="true" | ||
> | ||
foo | ||
</div> | ||
`) | ||
}) | ||
|
||
it('can render as other element types', () => { | ||
renderJsx(<Box as="span">foo</Box>) | ||
expect(getByText('foo')).toMatchInlineSnapshot(` | ||
<span> | ||
foo | ||
</span> | ||
`) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Clickable } from '.' | ||
import { renderJsx, getByText, pressSpace, pressEnter } from '../../test/utils' | ||
|
||
describe('Clickable', () => { | ||
it('renders correctly', () => { | ||
renderJsx(<Clickable>foo</Clickable>) | ||
expect(getByText('foo')).toMatchInlineSnapshot(` | ||
<div | ||
tabindex="0" | ||
> | ||
foo | ||
</div> | ||
`) | ||
}) | ||
|
||
it('emits click event on press space', () => { | ||
const clickHandler = jest.fn() | ||
renderJsx(<Clickable onClick={clickHandler}>foo</Clickable>) | ||
pressSpace(getByText('foo')) | ||
expect(clickHandler).toBeCalledTimes(1) | ||
}) | ||
|
||
it('emits no click event on keydown space when disabled', () => { | ||
const clickHandler = jest.fn() | ||
renderJsx( | ||
<Clickable onClick={clickHandler} disabled> | ||
foo | ||
</Clickable> | ||
) | ||
pressSpace(getByText('foo')) | ||
expect(clickHandler).toBeCalledTimes(0) | ||
}) | ||
|
||
it('emits only one click event on press space as button', () => { | ||
const clickHandler = jest.fn() | ||
renderJsx( | ||
<Clickable onClick={clickHandler} as="button"> | ||
foo | ||
</Clickable> | ||
) | ||
pressSpace(getByText('foo')) | ||
expect(clickHandler).toBeCalledTimes(1) | ||
}) | ||
|
||
it('emits click event on press enter', () => { | ||
const clickHandler = jest.fn() | ||
renderJsx(<Clickable onClick={clickHandler}>foo</Clickable>) | ||
pressEnter(getByText('foo')) | ||
expect(clickHandler).toBeCalledTimes(1) | ||
}) | ||
|
||
it('emits no click event on press enter when disabled', () => { | ||
const clickHandler = jest.fn() | ||
renderJsx( | ||
<Clickable onClick={clickHandler} disabled> | ||
foo | ||
</Clickable> | ||
) | ||
pressEnter(getByText('foo')) | ||
expect(clickHandler).toBeCalledTimes(0) | ||
}) | ||
|
||
it('emits only one click event on press enter as button', async () => { | ||
const clickHandler = jest.fn() | ||
renderJsx( | ||
<Clickable onClick={clickHandler} as="button"> | ||
foo | ||
</Clickable> | ||
) | ||
pressEnter(getByText('foo')) | ||
expect(clickHandler).toBeCalledTimes(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
Oops, something went wrong.