I have a basic HTML Table that renders some input data from Redux. I want to test to see that Object 1 renders properly in <tr></tr> 1, Object 2 renders properly in <tr></tr> 2, etc.
Table Component
import React, { PropTypes } from 'react';
let getBudgetItems = (budgets) => {
return budgets.map((budget, key) => {
return (
<tr className = "add-budget-table-row" key={"budget_item_" + key}>
<td>{budget.budgetCategory}</td>
<td>${budget.budgetCost}</td>
<td>{budget.budgetDate}</td>
<td><button className="btn btn-primary">Edit Budget</button></td>
</tr>
);
});
};
const RenderBudgetTable = ({ budgets }) => {
return (
<div className="table-responsive">
<table className="table table-hover add-budget-table">
<thead>
<tr>
<th>Budget Name</th>
<th>Monthly Cost</th>
<th>Due Date</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
{getBudgetItems(budgets)}
</tbody>
</table>
</div>
);
};
RenderBudgetTable.propTypes = {
budgets : PropTypes.array
};
export default RenderBudgetTable;
Test
describe("Budget data from redux store renders into form on budget edit page", () => {
let simulatedBudgets = [ expectedBudget_1, expectedBudget_2 ];
let wrapper = setupMount(null, simulatedBudgets);
it("Renders a valid bootstrap table", () => {
expect(wrapper.find('.add-budget-table').length).toBe(1);
});
it("Renders two different budget items into the table", () => {
expect(wrapper.find('.add-budget-table-row').length).toEqual(2);
console.log(wrapper.find('.add-budget-table-row').nodes[0].HTMLTableRowElement);
});
Obviously, getting by node index isn't favorable and also isn't working. The length for the table is working, since I have an arbitrary className attached to each row instance.