Test React element height with Jest

天涯浪子 提交于 2019-12-01 18:03:35

Jest "runs your tests with a fake DOM implementation (via jsdom) so that your tests can run on the command line" (http://facebook.github.io/jest/).

I would not expect something like the element height to be set, since it's not being run against a rendering engine to work out the height of any divs.

I would suggest setting a marker style class on the div in either state or both ("read-more" / "read-less"). Then your test can assert the presence or absence of a class.

Also - if you don't set the style attribute at all in "read more" mode, the enclosing div should be rendered to fully show the inner div (unless you're not just trying to show the whole inner div). So wouldn't it be adequate to test that the style attribute has the this.props.collapsedHeight value in "read less" mode, and is not set in "read more" mode?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!