Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help: Test Extension #26

Open
lsntdev opened this issue Jul 20, 2022 · 0 comments
Open

Help: Test Extension #26

lsntdev opened this issue Jul 20, 2022 · 0 comments

Comments

@lsntdev
Copy link

lsntdev commented Jul 20, 2022

I would like to know how we can test the extension, seems that getPluginForTest wont get the extension, Here are the sample of test I was trying to do:

const expect = require('expect');
import React from 'react';
import ReactDOM from 'react-dom';

import { MyExtension } from '../extension/plugins/Extension';
import { getPluginForTest } from '../../MapStore2/web/client/plugins/__tests__/pluginsTestUtils';
import { createStateMocker } from '../../MapStore2/web/client/reducers/__tests__/reducersTestUtils';
import controlsReducer from '../../MapStore2/web/client/reducers/controls';

const DUMMY_ACTION = { type: "DUMMY_ACTION" };

describe('MyExtension', () => {
    const stateMocker = createStateMocker({ controls: controlsReducer });
    beforeEach((done) => {
        document.body.innerHTML = '<div id="container"></div>';
        setTimeout(done);
    });

    afterEach((done) => {
        ReactDOM.unmountComponentAtNode(document.getElementById("container"));
        document.body.innerHTML = '';
        setTimeout(done);
    });
    it('is open?', () => {
        const {Plugin, containers} = getPluginForTest(MyExtension, stateMocker(DUMMY_ACTION), {BurgerMenuPlugin: {}});
        expect(Object.keys(containers)).toContain('BurgerMenu');
        ReactDOM.render(<Plugin />, document.getElementById("container"));
        console.log(document.getElementById("container").innerHTML);
        expect(true).toBe(true);
    });
});

I got the following:

MyExtension
    ✖ is open?
20 07 2022 16:56:10.334:WARN [Chrome Headless 103.0.5060.134 (Linux x86_64)]: Disconnected (0 times), because no message in 30000 ms.
Chrome Headless 103.0.5060.134 (Linux x86_64) ERROR
  Disconnected, because no message in 30000 ms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant