2
我試圖用酶在組件上執行虛擬測試。測試即將檢查上下文。即使我正在編寫與酶文檔相同的代碼,上下文總是空的。用酶測試反應組分與上下文:返回一個空物體
import React from 'react';
import { shallow } from 'enzyme';
import Overlay from '../../../../app/components/Overlay/Overlay';
describe('<Overlay />',() => {
it.only('return a context',() => {
const wrapper = shallow(<Overlay />, { context: { foo: 10 } });
console.log(wrapper.context());
// expect(wrapper.context().foo).to.equal(10);
});
})
測試的輸出是:
<Overlay />
{}
✓ return a context
我在哪裏錯了?