Unit testing on the stack "reaction + reaction-route"

I read a lot of recommendations on how to render routing through relay components, but I still can't get it to work. I tried to find it by searching the github database, but still no luck. And at this stage I need only one working example.

Here is my template project , but maybe that doesn't matter. I just want to see some working example of testing a modular route.

+2
source share
2 answers

I got my job after I found a top-secret hidden router testing guide .

, Object.assign , sinon.js, , .

EDIT: , , . . , ?

: Jest, , :

  • mocha ( ), require, jsx :
    var fs = require("fs");
    var reactTools = require("react-tools");

    require.extensions[".jsx"] = function(module, filename) {
      var jsxContent = fs.readFileSync(filename).toString();
      var jsContent = reactTools.transform(jsxContent);
      return module._compile(jsContent, filename);
    };
  1. DOM. JSDOM . domino.
    var domino = require("domino");

    global.window = domino.createWindow();
    global.document = global.window.document;

     //Set the NODE_ENV so we can call `render`.
     //Otherwise we get an error from react about server rendering. :(

    process.env.NODE_ENV = "test";
  1. - DOM React.render():
      var MyComponent = fakeRouter(require("./MyComponent.jsx"));
      var component = React.render( 
        < MyComponent / > ,
        document.body
      );
      node = component.getDOMNode();
       //I used `zepto-node` and `chai-jq` to assert against my components
0

(, v4) , , , MemoryRouter, .

import {MemoryRouter} from 'react-router-dom';
import {render} from 'react-dom';

render(<MemoryRouter>
  <YourComponent>
</MemoryRouter>, node, () => {});
0

Source: https://habr.com/ru/post/1599157/


All Articles