Chapter 5 - Testing Article
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { render, screen } from '@redwoodjs/testing'
|
||||
import { render, screen, within } from '@redwoodjs/testing'
|
||||
import { Loading, Empty, Failure, Success } from './ArticlesCell'
|
||||
import { standard } from './ArticlesCell.mock'
|
||||
|
||||
@@ -25,9 +25,15 @@ describe('ArticlesCell', () => {
|
||||
const articles = standard().articles
|
||||
render(<Success articles={articles} />)
|
||||
|
||||
expect(screen.getByText(articles[0].title)).toBeInTheDocument()
|
||||
expect(screen.getByText(articles[0].body)).toBeInTheDocument()
|
||||
expect(screen.getByText(articles[1].title)).toBeInTheDocument()
|
||||
expect(screen.getByText(articles[1].body)).toBeInTheDocument()
|
||||
articles.forEach((article) => {
|
||||
const truncatedBody = article.body.substring(0, 10)
|
||||
const matchedBody = screen.getByText(truncatedBody, { exact: false })
|
||||
const ellipsis = within(matchedBody).getByText('...', { exact: false })
|
||||
|
||||
expect(screen.getByText(article.title)).toBeInTheDocument()
|
||||
expect(screen.queryByText(article.body)).not.toBeInTheDocument()
|
||||
expect(matchedBody).toBeInTheDocument()
|
||||
expect(ellipsis).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user