Skip to content

Commit

Permalink
Use screen instead of destructing render (#21)
Browse files Browse the repository at this point in the history
# Use screen instead of destructing render

## ♻️ Current situation & Problem

Destructing `render` to get selectors binds result of render to
selectors. Sometimes it's unwanted, especially if creating some reusable
functions across the tests.

This binding is completely unnecessary, doesn't benefit tests
readability and ease of development. It's easier to use `screen`
everywhere, because of auto-completion and lack of maintenance of
destructed properties.

## ⚙️ Release Notes 
* Use screen instead of destructing render


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).

---------

Co-authored-by: Paul Schmiedmayer <[email protected]>
  • Loading branch information
arkadiuszbachorski and PSchmiedmayer authored May 29, 2024
1 parent 77fec26 commit 5ce0539
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions app/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@
// SPDX-License-Identifier: MIT
//

import React from 'react'
import { render } from '@testing-library/react'
import { render, screen } from '@testing-library/react'
import '@testing-library/jest-dom'
import Home from './page'

describe('Home Component', () => {
it('renders the Stanford Biodesign Digital Health Next.js Template heading', () => {
const { getByText } = render(<Home />)
render(<Home />)

const headingElement = getByText(
const headingElement = screen.getByText(
/Welcome to the Stanford Biodesign Digital Health Next.js Template/i,
)

expect(headingElement).toBeInTheDocument()
})

it('renders the Stanford Biodesign Logo', () => {
const { getByAltText } = render(<Home />)
render(<Home />)

const imageElement = getByAltText(
const imageElement = screen.getByAltText(
'Stanford Biodesign Logo',
) as HTMLImageElement

Expand Down

0 comments on commit 5ce0539

Please sign in to comment.