- Mastering React Test:Driven Development
- Daniel Irvine
- 260字
- 2021-06-24 14:45:05
Initial selection of data
Let's start by asserting that each li element has a button element:
- First up, let's display a message to the user if there are no appointments scheduled for today. In the AppointmentsDayView describe block, add this test:
it('initially shows a message saying there are no appointments today', () => {
render(<AppointmentsDayView appointments={[]} />);
expect(container.textContent).toMatch(
'There are no appointments scheduled for today.'
);
});
- Make that pass by adding in a message at the bottom of rendered output. We don't need a check for an empty appointments array just yet; we'll need another test to triangulate to that:
return (
<div id="appointmentsDayView">
...
<p>There are no appointments scheduled for today.</p>
</div>
);
- If there are appointments scheduled, then we start off by showing the first one of the day. We can check for a rendered customer firstName to determine whether the right customer is shown:
it('selects the first appointment by default', () => {
render(<AppointmentsDayView appointments={appointments} />);
expect(container.textContent).toMatch('Ashley');
});
- Since we're looking for the customer name, we'll need to make sure that's available in the appointments array. Update it now to include the customer firstName:
const appointments = [
{
startsAt: today.setHours(12, 0),
customer: { firstName: 'Ashley' }
},
{
startsAt: today.setHours(13, 0),
customer: { firstName: 'Jordan' }
}
];
- Let's make that pass by using our Appointment component. Modify the last line of the div component to read as follows:
<div id="appointmentsDayView">
// ... existing code here ...
{appointments.length === 0 ? (
<p>There are no appointments scheduled for today.</p>
) : (
<Appointment {...appointments[0]} />
)}
</div>
Now, we're ready to let the user make a selection.
推薦閱讀
- 嵌入式軟件系統(tǒng)測試:基于形式化方法的自動化測試解決方案
- 編程珠璣(續(xù))
- STM32F0實(shí)戰(zhàn):基于HAL庫開發(fā)
- WordPress 4.0 Site Blueprints(Second Edition)
- FPGA Verilog開發(fā)實(shí)戰(zhàn)指南:基于Intel Cyclone IV(進(jìn)階篇)
- 微服務(wù)架構(gòu)深度解析:原理、實(shí)踐與進(jìn)階
- C語言開發(fā)基礎(chǔ)教程(Dev-C++)(第2版)
- RESTful Java Web Services(Second Edition)
- Struts 2.x權(quán)威指南
- Oracle 12c從入門到精通(視頻教學(xué)超值版)
- Learning Grunt
- Greenplum構(gòu)建實(shí)時數(shù)據(jù)倉庫實(shí)踐
- 創(chuàng)新工場講AI課:從知識到實(shí)踐
- Improving your Penetration Testing Skills
- Oracle API Management 12c Implementation