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 (

& lt; topbar / & gt; Lt; / div & gt;)}}); Module Exports = Designer Pages;

Topbear component

  / ** @jsx response Dom * / var response = required ("response"); Var TopBar = React.createClass ({rendere: function () {Return (& lt; nav className = "top-bar"> );}}); Module.exports = TopBar;   

Now, I want to test whether the DesignerPage component has TopBar component. Here's what I should do:

  / ** @ 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);});});   

But It does not pass ...: (

  $ ./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    

I did not run the code in question But line:

  Var topbar = testUtils.scryRenderedComponentsWithType (page, 'TopBar');   

I'm skeptical. It seems that you should give a componentClass a string.

I think how could this possibly use the string to identify the component type. This could potentially be identified by string using displayName , but I suspect it will do this.

I think you want public relations responsibly:

  var TopBar = required ('../../ src / JS / page / designer page '); Var topbar = TestUtils.scryRenderedComponentsWithType (Page, Topbar);    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -