0

I'm working with a React-Router test stubbing example, and I've never seen this class convention before. I'm guessing this is ES6 specific?

var stubRouterContext = (Component, props, stubs) => {
    function RouterStub() { }

    Object.assign(RouterStub, {
        makePath () {},
        makeHref () {},
        transitionTo () {},
        replaceWith () {},
        goBack () {},
        getCurrentPath () {},
        getCurrentRoutes () {},
        getCurrentPathname () {},
        getCurrentParams () {},
        getCurrentQuery () {},
        isActive () {},
        getRouteAtDepth() {},
        setRouteComponentAtDepth() {}
    }, stubs);

    return React.createClass({
        childContextTypes: {
            router: React.PropTypes.func,
            routeDepth: React.PropTypes.number
        },

        getChildContext () {
            return {
                router: RouterStub,
                routeDepth: 0
            };
        },

        render () {
            return <Component {...props} />
        }
    });
};

And why do I get TypeError: object is not function when I do this?

var Subject = stubRouterContext(Handler, props);

Here's the link to the doc https://github.com/rackt/react-router/blob/master/docs/guides/testing.md

4m1r
  • 12,234
  • 9
  • 46
  • 58

1 Answers1

0

It is ES6 specific, it's the arrow shorthand: https://github.com/lukehoban/es6features#arrows

"Arrows are a function shorthand using the => syntax. They are syntactically similar to the related feature in C#, Java 8 and CoffeeScript."

aaron-coding
  • 2,571
  • 1
  • 23
  • 31