Skip to content

Commit

Permalink
fix: change the type of record as optional
Browse files Browse the repository at this point in the history
  • Loading branch information
KimJoonSeo committed Feb 1, 2024
1 parent 1cae139 commit b4fe728
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/ScoreCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Team: React.FC<TeamInfo> = (props) => {
</div>
</div>
}
description={`(${props.records[0].summary})`}
description={`(${props.records ? props.records[0].summary : '0-0-0'})`}
/>
)
}
Expand Down
9 changes: 6 additions & 3 deletions src/tests/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import { rest } from 'msw'
describe('App component', () => {
test('should render App successfully', async () => {
renderWithClient(<App />)
const summary =
mockData.events[0].competitions[0].competitors[0].records[0].summary
expect(await screen.findByText('(' + summary + ')')).toBeInTheDocument()
if(mockData.events[0].competitions[0].competitors[0].records) {
const summary =
mockData.events[0].competitions[0].competitors[0].records[0].summary
// eslint-disable-next-line jest/no-conditional-expect
expect(await screen.findByText('(' + summary + ')')).toBeInTheDocument()
}
})

test('should render App successfully when data is empty', async () => {
Expand Down
27 changes: 15 additions & 12 deletions src/tests/ScoreCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ import { render, screen } from '@testing-library/react'

describe('ScoreCard', () => {
test('renders a record of team', () => {
render(
<ScoreCard
status={mockData.events[0].status}
competitions={mockData.events[0].competitions}
/>,
)
const recordElement = screen.getByText(
'(' +
mockData.events[0].competitions[0].competitors[0].records[0].summary +
')',
)
expect(recordElement).toBeInTheDocument()
render(
<ScoreCard
status={mockData.events[0].status}
competitions={mockData.events[0].competitions}
/>,
)
if(mockData.events[0].competitions[0].competitors[0].records) {
const recordElement = screen.getByText(
'(' +
mockData.events[0].competitions[0].competitors[0].records[0].summary +
')',
)
// eslint-disable-next-line jest/no-conditional-expect
expect(recordElement).toBeInTheDocument()
}
})
})
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface Competition {
export interface Competitor {
id: string
score: string
records: [
records?: [
{
summary: string
},
Expand Down

0 comments on commit b4fe728

Please sign in to comment.