2
我想測試與酶的組成部分,我收到以下錯誤測試鏈接:與酶
Warning: Failed context type: The context `history` is marked as required in `Link`, but its value is `undefined`.
in Link (at UserTable.js:30)
in button (created by Button)
in Button (at UserTable.js:29)
in td (at UserTable.js:28)
in tr (at UserTable.js:24)
in tbody (at UserTable.js:43)
in table (created by Table)
in Table (at UserTable.js:41)
in UserTable (at UserTable.test.js:19)
這裏是我的測試:
import React from 'react';
import { render } from 'enzyme';
import { fromJS } from 'immutable';
import { Table } from 'react-bootstrap';
import UserTable from '../UserTable';
const users = fromJS([{
id: 2026429,
login: 'rahulthewall',
avatar_url: 'https://avatars1.githubusercontent.com/u/2026429?v=3',
login: 'rahulthewall',
html_url: 'https://github.com/rahulthewall',
}]);
describe('<UserTable />',() => {
// Prepare the components
const context = { router: { isActive: (a, b) => true } };
const wrapper = render(
<UserTable users={users} />,
{ context }
);
const table = wrapper.find('table');
const thead = table.find('thead');
const tbody = table.find('tbody');
const headerRow = thead.find('tr');
const bodyRows = tbody.find('tr');
it('renders the table header',() => {
expect(headerRow.length).toEqual(1);
expect(headerRow.find('th').length).toEqual(4);
});
it('renders the table data',() => {
expect(bodyRows.length).toEqual(1);
expect(bodyRows.find('td').length).toEqual(4);
});
});
所以我的問題是,如何渲染時,是否將歷史上下文傳遞給組件?我有點迷失在這裏。