This video was part of the The Complete React on Rails 5 Course.
A new version of the course is now available
npm install —save-dev react-test-renderer
import React from 'react'; import ReactDOM from 'react-dom'; import Appointment from '../components/Appointment'; import { BrowserRouter as Router } from 'react-router-dom'; import { shallow, mount } from 'enzyme'; import renderer from 'react-test-renderer';
expect(appointment.contains(appt_time)).toEqual(true); }) test('renders appointment correctly', () =>{
describe('render', () => { it('should display the appointment title', () => { const appointment = mount(<Router><Appointment appointment={{id:1, title: 'Team standup meeting', appt_time: new Date()}} /></Router>); const title = <h3>Team standup meeting</h3>; expect(appointment.contains(title)).toEqual(true); })
describe('render', () => { it('should display the appointment title', () => { const appointment = mount(<Router><Appointment appointment={{id:1, title: 'Team standup meeting', appt_time: new Date()}} /></Router>); const title = <h3>Team standup meeting</h3>; expect(appointment.contains(title)).toEqual(true); })
it('renders appointment correctly', () =>{ const appointment = mount(<Router><Appointment appointment={{id:1, title: 'Team standup meeting', appt_time: new Date('04/11/2017, 12:00:00')}} /></Router>); })
it('renders appointment correctly', () =>{ const appointment = mount(<Router><Appointment appointment={{id:1, title: 'Team standup meeting', appt_time: new Date('04/11/2017, 12:00:00')}} /></Router>); let tree = appointment.toJSON(); })
const appointment = renderer.create(<Router>
it('renders appointment correctly', () =>{ const appointment = renderer.create(<Router><Appointment appointment={{id:1, title: 'Team standup meeting', appt_time: new Date('04/11/2017, 12:00:00')}} /></Router>); let tree = appointment.toJSON(); expect(tree).toMatchSnapshot(); }) });
exports[`render renders appointment correctly 1`] = ` <div className="appointment"> <a href="/appointments/1" onClick={[Function]}> <h3> Team standup meeting </h3> </a> <p> April 11 2017, 12:00:00 pm </p> <a href="/appointments/1/edit" onClick={[Function]}> Edit </a> </div> `;
const appointment = mount(<Router><Appointment appointment={{id:1, title: 'Team standup meeting', appt_time: new Date()}} /></Router>);
<Appointment appointment={{id:1, title: 'Team standup meeting', appt_time: new Date('04/11/2017, 12:00:00')}} /></Router>);
This lesson was part of the The Complete React on Rails 5 Course.