unit testing - How to test whether a React Component contains another component with jest? -
I am trying to use jest-cli to test whether a response component has its output in the second Is the component.
Designer Page Component [...] Top TopBar = Required ('../class / Layout / topbar .js'); Var Designer Page = React .createclass ({getInitialState: function () {var state = {}} return state;}, render: function () {Return ( Topbear component Now, I want to test whether the DesignerPage component has TopBar component. Here's what I should do: But It does not pass ...: ( I did not run the code in question But line: I'm skeptical. It seems that you should give a I think how could this possibly use the string to identify the component type. This could potentially be identified by string using I think you want public relations responsibly:
/ ** @jsx response Dom * / var response = required ("response"); Var TopBar = React.createClass ({rendere: function () {Return (& lt; nav className = "top-bar"> );}}); Module.exports = TopBar;
/ ** @ jsx response Dom * / jest.dontMock ('../../ src / js / pages / designerpage.js'); Describe ('designer page', function () (this should be 'topbier', function) (var response = is required ('response / additional'); var designer page = required ('../../) / Js /pages/DesignerPage.js'); var TestUtils = React.addons.TestUtils; // Provide a Designer Page in the Document var page = TestUtils.renderIntoDocument (& lt; DesignerPage / & gt;); // Verify That TopBar includes var Topbar = TestUtils.scryRenderedComponentsWithType (page, 'topbird'); Hopefully (topbar.length) .toBe (1);});});
$ ./node_modules/jest-cli/bin/jest.js DesignerPage found 1 matching test ... failed __ tests __ / page / designer page-trial .js (4.175s) a designer page รข € "this included a TopBar - estimated: 0 toBe: 1 spec. & Lt; anonymous & gt; (__tests __ / page / designer page-test .js: 16: 27) timer.listOnTimeout [timer] as timer (timer. JS: 112: 15) 1 test failed, passed 0 exams (1 total) Run time: 6.462s
Var topbar = testUtils.scryRenderedComponentsWithType (page, 'TopBar');
componentClass a string.
displayName , but I suspect it will do this.
var TopBar = required ('../../ src / JS / page / designer page '); Var topbar = TestUtils.scryRenderedComponentsWithType (Page, Topbar);
Comments
Post a Comment