我有以下React组件:
read()
我还有一个测试文件,用于检查uart0_filestream = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
功能,效果很好:
const titleText = translate('header.about');
const About = ({onClose}) => (
<div>
<ModalHeader title={titleText} onClose={onClose} />
<Content />
</div>
);
但是,运行测试时,我在终端中收到以下警告:
onClose
仅在运行测试时,我才在浏览器中未收到警告。虽然这只是一个警告,但我宁愿解决此问题。
有什么方法可以给const spy = sinon.spy();
const wrapper = shallow(<About onClose={spy} />); // I also tried "mount()"
...
assert.equal(spy.callCount, 1, 'onClose was called exactly once');
赋予模拟值?我只对模拟局部变量的可能解决方案感兴趣(即本示例中的Warning: Failed prop type: The prop `title` is marked as required in `ModalHeader`, but its value is `undefined`
)。
答案 0 :(得分:0)
使用笑话,您可以像这样模拟翻译包:
// this will mock the translate package
jest.mock('translate', () => () => 'some test title');
const spy = sinon.spy();
const wrapper = shallow(<About onClose={spy} />);
...
assert.equal(spy.callCount, 1, 'onClose was called exactly once');
答案 1 :(得分:0)
使用
TcpClient