Closed denis88k closed 1 month ago
import React from 'react'
import { LottiePlayer } from '../index'
import Animation from './Animation.json' // animation json
import { render } from '@testing-library/react'
describe('LottiePlayer', () => {
const src = 'https://assets3.lottiefiles.com/packages/lf20_UJNc2t.json' // your link src animation json
const dataTestid= 'LottiePlayer'
beforeEach(() => {
global.fetch = jest.fn().mockImplementation(() =>
Promise.resolve({
json: () => Promise.resolve(Animation),
})
) as jest.Mock
})
afterEach(() => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
global.fetch.mockRestore()
})
it('default player', async () => {
const { findByDataTestid} = render(
<LottiePlayer
src={src}
loop={true}
data-testid={dataTestid}
/>
)
expect(await findByDataTestid(dataTestid)).toMatchSnapshot()
})
})
hi) I wrote a snapshot test for my component, but received a component with an error
my component:
my test:
result test:
Based on the library code, I realized that such an error could occur if it was not possible to obtain the json file Maybe someone has tested this component, I can’t find any tests written in react-testing-library