5180 fichiers 38.5 Mo 0 téléchargements 206 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / components / plugins / OctanePluginApi.test.ts
OctanePluginApi.test.ts 1.3 Ko Télécharger le fichier
/* @vitest-environment jsdom */

import { describe, expect, it, vi } from 'vitest';
import { getRegisteredPlugins, pluginApi, subscribePlugins } from './OctanePluginApi';

describe('plugin registration', () => {
    it('lists a plugin only once its onInit went through', () => {
        const error = vi.spyOn(console, 'error').mockImplementation(() => undefined);

        pluginApi.register({
            name: 'broken-start',
            label: 'Broken start',
            onOpen: () => undefined,
            onInit: () => {
                throw new Error('boom');
            }
        });

        expect(getRegisteredPlugins().some((plugin) => plugin.name === 'broken-start')).toBe(false);
        error.mockRestore();
    });

    it('tells every listener about a change even when one of them throws', () => {
        const error = vi.spyOn(console, 'error').mockImplementation(() => undefined);
        const heard = vi.fn();
        const stopBroken = subscribePlugins(() => {
            throw new Error('listener');
        });
        const stopHeard = subscribePlugins(heard);

        pluginApi.register({ name: 'listener-check', label: 'Listener check', onOpen: () => undefined });

        expect(heard).toHaveBeenCalled();
        stopBroken();
        stopHeard();
        error.mockRestore();
    });
});
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser