升级React从0.13升级到v0.14.0-beta3后,我在单元测试中收到了很多警告:
Warning: ReactDOMComponent: Do not access .props of a DOM node; instead,recreate the props as `render` did originally or read the DOM properties/attributes directly from this node (e.g.,this.refs.Box.className). This DOM node was rendered by `Button`.
它们是由我的单元测试引起的,例如:
it('should render to a <a> when href is given',function () { var button = TestUtils.renderIntoDocument(<Button className="amazon" href="#">Hello</Button>); expect(TestUtils.scryRenderedDOMComponentsWithTag(button,'button').length).toBe(0); expect(TestUtils.scryRenderedDOMComponentsWithTag(button,'a').length).toBe(1); expect(TestUtils.scryRenderedDOMComponentsWithTag(button,'a')[0].props.href).toBe('#'); expect(TestUtils.scryRenderedDOMComponentsWithTag(button,'a')[0].props.className).toBe('amazon Button'); });
我该如何解决?有没有推荐的这样测试DOM元素的做法?