-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vue-masonry): add proper image handling
- Loading branch information
1 parent
8eac1d1
commit 350f3e8
Showing
3 changed files
with
95 additions
and
21 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,21 +1,43 @@ | ||
import { render, RenderResult } from '@testing-library/vue'; | ||
import { fireEvent, render } from '@testing-library/vue'; | ||
import VueMasonry from './VueMasonry.vue'; | ||
|
||
describe('VueMasonry.vue', () => { | ||
let harness: RenderResult; | ||
|
||
beforeEach(() => { | ||
harness = render(VueMasonry, { | ||
test('renders component with images', async () => { | ||
const { getByText, getByTestId } = render(VueMasonry, { | ||
stubs: ['nuxt-link'], | ||
slots: { | ||
default: '<div>VueMasonry</div>', | ||
default: | ||
'<div><img data-testid="image" alt="test" src="https://images.unsplash.com/photo-1567017469553-d1b219af5831?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8bW9udGFpbnN8ZW58MHx8MHx8&auto=format&fit=crop&w=900&q=60" />VueMasonry</div>', | ||
}, | ||
}); | ||
|
||
getByText('VueMasonry'); | ||
|
||
const image = getByTestId('image'); | ||
|
||
await fireEvent.load(image); | ||
expect(image.style.display).toBe('initial'); | ||
|
||
await fireEvent.error(image); | ||
expect(image.style.display).toBe('none'); | ||
}); | ||
|
||
test('renders component', () => { | ||
const { getByText } = harness; | ||
test('renders component with images and calls original events', async () => { | ||
const { getByText, getByTestId } = render(VueMasonry, { | ||
stubs: ['nuxt-link'], | ||
slots: { | ||
default: | ||
'<div><img data-testid="image" alt="test" src="https://images.unsplash.com/photo-1567017469553-d1b219af5831?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8bW9udGFpbnN8ZW58MHx8MHx8&auto=format&fit=crop&w=900&q=60" onload="this.style.height=`24px`" onerror="this.style.width=`24px`" />VueMasonry</div>', | ||
}, | ||
}); | ||
const image = getByTestId('image'); | ||
|
||
await fireEvent.load(image); | ||
await fireEvent.error(image); | ||
|
||
getByText('VueMasonry'); | ||
|
||
expect(image.style.height).toBe('24px'); | ||
expect(image.style.width).toBe('24px'); | ||
}); | ||
}); |
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