Skip to content

Commit

Permalink
Test tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
tanem committed Jan 23, 2023
1 parent e5c64c7 commit f192ecd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions test/__snapshots__/browser.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,14 @@ exports[`while running in a browser environment should render correctly with an
"
`;

exports[`while running in a browser environment should render the specified fallback if afterInjection fails 1`] = `
exports[`while running in a browser environment should render the specified fallback if afterInjection throws an error 1`] = `
"<div>
<span>fallback</span>
</div>
"
`;

exports[`while running in a browser environment should render the specified fallback if beforeInjection fails 1`] = `
exports[`while running in a browser environment should render the specified fallback if beforeInjection throws an error 1`] = `
"<div>
<span>fallback</span>
</div>
Expand Down
22 changes: 12 additions & 10 deletions test/browser.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ describe('while running in a browser environment', () => {
expect(div.innerHTML).toMatchPrettyHtmlSnapshot()
})

it('should render the specified fallback if beforeInjection fails', async () => {
it('should render the specified fallback if beforeInjection throws an error', async () => {
const fallback = () => <span>fallback</span>

const uuid = faker.datatype.uuid()
Expand All @@ -366,10 +366,11 @@ describe('while running in a browser environment', () => {
)

await waitFor(() => screen.findByText('fallback'))

expect(container.innerHTML).toMatchPrettyHtmlSnapshot()
})

it('should call onError if beforeInjection fails', (done) => {
it('should call onError if beforeInjection throws an error', (done) => {
expect.assertions(1)

const uuid = faker.datatype.uuid()
Expand All @@ -384,16 +385,16 @@ describe('while running in a browser environment', () => {
beforeInjection={() => {
throw error
}}
onError={(error) => {
expect(error).toEqual(error)
onError={(e) => {
expect(e).toEqual(error)
done()
}}
src={`http://localhost/${uuid}.svg`}
/>
)
})

it('should render the specified fallback if afterInjection fails', async () => {
it('should render the specified fallback if afterInjection throws an error', async () => {
const fallback = () => <span>fallback</span>

const uuid = faker.datatype.uuid()
Expand All @@ -405,7 +406,7 @@ describe('while running in a browser environment', () => {
const { container } = render(
<ReactSVG
afterInjection={() => {
throw new Error('test error')
throw new Error('sad trombone')
}}
fallback={fallback}
src={`http://localhost/${uuid}.svg`}
Expand All @@ -417,10 +418,11 @@ describe('while running in a browser environment', () => {
expect(container.innerHTML).toMatchPrettyHtmlSnapshot()
})

it('should call onError if afterInjection fails', (done) => {
it('should call onError if afterInjection throws an error', (done) => {
expect.assertions(1)

const uuid = faker.datatype.uuid()
const error = new Error('sad trombone')

nock('http://localhost')
.get(`/${uuid}.svg`)
Expand All @@ -429,10 +431,10 @@ describe('while running in a browser environment', () => {
render(
<ReactSVG
afterInjection={() => {
throw new Error('test error')
throw error
}}
onError={(error) => {
expect(error).toEqual(new Error('test error'))
onError={(e) => {
expect(e).toEqual(error)
done()
}}
src={`http://localhost/${uuid}.svg`}
Expand Down

0 comments on commit f192ecd

Please sign in to comment.