Skip to content

Cannot get content when write unit test using Vitest #207

@fpt-tom-du

Description

@fpt-tom-du

I got error: Unable to find an accessible element with the role "listitem".
I cannot get list of content to test action on that.

import {render, screen} from '@testing-library/react'
import {FileArray, FileBrowser} from 'chonky'
import {describe, expect, it} from 'vitest'

const DATA: {data: FileArray} = {
  data: [
    {
      name: '2024-02-05.jpg',
      id: '2024-02-05.jpg',
      thumbnailUrl: 'TEST',
      size: 122161,
      modDate: '2024-06-12T02:03:31.000Z'
    }
  ]
}

describe('FileBrowser', () => {
  it('should display file list', () => {
    render(<FileBrowser files={DATA.data} />)

    const fileItems = screen.getAllByRole('listitem')
    expect(fileItems).toHaveLength(2)
    expect(fileItems[0]).toHaveTextContent('2024-02-05.jpg')
  })
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions