How to use the @storybook/addons.__channel function in @storybook/addons

To help you get started, we’ve selected a few @storybook/addons examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vertexbz / storybook-addon-react-live-edit / src / __tests__ / component / LivePreview.spec.js View on Github external
it('should display error', () => {
        const channel = addonsMock.getChannel();
        const code = 'source code';
        const scope = {};

        const wrapper = shallow(
            
        );


        expect(addonsMock.__channel.on).toBeCalledTimes(1);
        expect(addonsMock.__channel.on).toBeCalledWith(event.UpdateSource, expect.any(Function));

        expect(addonsMock.__channel.emit).toBeCalledTimes(1);
        expect(addonsMock.__channel.emit).toBeCalledWith(event.LoadSource, code);


        expect(wrapper.find(ErrorDisplay).exists()).toBeTruthy();


        wrapper.unmount();
        expect(addonsMock.__channel.removeListener).toBeCalledTimes(1);
        expect(addonsMock.__channel.removeListener).toBeCalledWith(event.UpdateSource, expect.any(Function));

        expect(addonsMock.__channel.emit).toBeCalledTimes(2);
        expect(addonsMock.__channel.emit).toBeCalledWith(event.LoadSource, null);
    });
github vertexbz / storybook-addon-react-live-edit / src / __tests__ / component / LivePreview.spec.js View on Github external
it('should display error', () => {
        const channel = addonsMock.getChannel();
        const code = 'source code';
        const scope = {};

        const wrapper = shallow(
            
        );


        expect(addonsMock.__channel.on).toBeCalledTimes(1);
        expect(addonsMock.__channel.on).toBeCalledWith(event.UpdateSource, expect.any(Function));

        expect(addonsMock.__channel.emit).toBeCalledTimes(1);
        expect(addonsMock.__channel.emit).toBeCalledWith(event.LoadSource, code);


        expect(wrapper.find(ErrorDisplay).exists()).toBeTruthy();


        wrapper.unmount();
        expect(addonsMock.__channel.removeListener).toBeCalledTimes(1);
        expect(addonsMock.__channel.removeListener).toBeCalledWith(event.UpdateSource, expect.any(Function));

        expect(addonsMock.__channel.emit).toBeCalledTimes(2);
        expect(addonsMock.__channel.emit).toBeCalledWith(event.LoadSource, null);
    });
github vertexbz / storybook-addon-react-live-edit / src / __tests__ / addLiveSource.spec.js View on Github external
const source = 'source';
        const localScope = { scopeVar: 'xxx' };
        const contextScope = { scopeVar: 'zzz', scopeVar2: 'yyy' };

        addLiveSource.addLiveSource(kind, source, localScope);

        expect(addLiveSource.add).toBeCalledWith(kind, expect.any(Function));

        const storyFn = addLiveSource.add.mock.calls[0][1];

        const renderedStory = mount(storyFn({ [symbol.Scope]: contextScope }));

        expect(renderedStory.type()).toBe(LivePreview);
        expect(renderedStory.prop('code')).toBe(source);
        expect(renderedStory.prop('scope')).toEqual({ ...contextScope, ...localScope });
        expect(renderedStory.prop('channel')).toBe(addonsMock.__channel);
    });
});