Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
jest tutorial
import React from 'react'
import {render, fireEvent} from '@testing-library/react'
import Restaurants from '../Restaurants'
import * as fixtures from '../fixtures'
import {calculateDistance} from '../utils'
describe("Restaurants Component", ()=>{
it("should render restaurants passed to it", ()=>{
// render function returns a handle
const {getAllByText} = render(<Restaurants list={fixtures.dummyRestaurants}/>)
// get elements matching regex
it("should be able to filter restaurants by distance from center", ()=>{
const {queryAllByText, getByTestId} = render(<Restaurants list={fixtures.dummyRestaurants}/>)
// following block set five different return value for five calls to calculateDistance
const inpDistance = getByTestId('inpDistance')
// fire change event on inpDistance to set distance
fireEvent.change(inpDistance, {target:{value: 100}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.