【发布时间】:2021-12-20 15:48:10
【问题描述】:
我创建了简单的 React 应用程序,需要添加按钮组件。不幸的是,我的代码不起作用。我该如何解决?按钮实现(React):
import React from 'react';
const Button = (props) => {
return <button className="button">
{props.children}
</button>;
}
export { Button };
测试代码:
import React from 'react';
import { shallow } from 'enzyme';
import Button from './Button';
describe('Button', () => {
/**
* children - button text
*/
it('Button with text', () => {
const component = shallow(<Button>Button</Button>);
expect(component.html()).toEqual('<button class="button">Button</button>');
});
});
测试错误:
Expected: "<button class=\"button\">Button</button>"
Received: null
【问题讨论】:
-
你的意思是测试不工作或代码
-
我的测试请求代码回答为 null 而不仅仅是一些东西
标签: javascript reactjs null frontend