Sha256: eb68ecda04ef23b6ed961fab3fc65587a7d09571003a5168960cca437e5104cf

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

/* global jest */

import React from 'react';
import SnapShot   from 'react-test-renderer';

import Screens from 'hippo/screens';
import ScreenDefinitions from 'hippo/screen-definitions';

export { Screens, ScreenDefinitions };

export function getScreenInstance(screenId) {
    return Screens.all.get(screenId).display();
}


class TestRouter {
    constructor() {
        Object.assign(this, {
            isActive:   jest.fn(),
            push:       jest.fn(),
            replace:    jest.fn(),
            createPath: jest.fn(),
            listen:     jest.fn(() => {
                this.unlisten = jest.fn();
                return this.unlisten;
            }),
        });
    }
}

function makeContext() {
    return {
        router: new TestRouter(),
    };
}

function childContextTypes() {
    return {
        router: React.PropTypes.object,
    };
}

export class Context {
    constructor() {
        this.childContextTypes = childContextTypes();
        this.context = makeContext();
    }
}

export function Snapshot(el) {
    class Wrapper extends React.Component {
        static childContextTypes = childContextTypes();

        getChildContext() {
            return this._childContext || (this._childContext = makeContext());
        }

        render() {
            return el;
        }
    }
    const snapshot = SnapShot.create(React.createElement(Wrapper, {}, el));
    return snapshot.toJSON();
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hippo-fw-0.9.7 client/hippo/testing/screens.js
hippo-fw-0.9.6 client/hippo/testing/screens.js
hippo-fw-0.9.5 client/hippo/testing/screens.js
hippo-fw-0.9.4 client/hippo/testing/screens.js
hippo-fw-0.9.3 client/hippo/testing/screens.js
hippo-fw-0.9.2 client/hippo/testing/screens.js
hippo-fw-0.9.1 client/hippo/testing/screens.js