How to use the fusion-test-utils.getService function in fusion-test-utils

To help you get started, we’ve selected a few fusion-test-utils 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 fusionjs / fusionjs / fusion-plugin-node-performance-emitter / src / __tests__ / index.node.js View on Github external
test('service - cannot track the same types more than once at a time', t => {
  const perfService = getService(
    createTestFixture,
    NodePerformanceEmitterPlugin
  );

  t.throws(() => perfService.start(), 'already running trackers cannot start');

  // Able to start now that we've stopped
  t.doesNotThrow(() => perfService.stop(), 'service can be stopped');
  t.doesNotThrow(
    () => perfService.start(),
    'service can run if the trackers are not active'
  );

  t.doesNotThrow(() => perfService.stop(), 'service can be stopped');
  t.doesNotThrow(
    () => perfService.stop(),
github fusionjs / fusionjs / fusion-plugin-react-redux / src / __tests__ / index.node.js View on Github external
tape('non-ssr routes', async t => {
  const reducer = (state, action) => ({test: action.payload || 1});
  const plugin = getService(appCreator(reducer), Redux);
  let mockCtx = {
    body: null,
    memoized: new Map(),
  };

  t.plan(1);
  if (!Redux.middleware) {
    t.end();
    return;
  }

  // $FlowFixMe
  await Redux.middleware(null, plugin)((mockCtx: any), () => Promise.resolve());
  t.notok(plugin.from((mockCtx: any)).store);
  t.end();
});
github fusionjs / fusionjs / create-fusion-plugin / templates / plugin / content / src / __tests__ / index.browser.js View on Github external
tape('browser middleware', async t => {
  const element = React.createElement('div');
  const ctx: any = {element, template: {body: []}, memoized: new Map()};
  const service = getService(appCreator(), Plugin);
  try {
    await (Plugin.middleware &&
      // $FlowFixMe
      Plugin.middleware(null, service)((ctx: any), () => Promise.resolve()));
  } catch (e) {
    t.ifError(e);
  }

  t.end();
});
github fusionjs / fusionjs / fusion-plugin-rpc-redux-react / src / __tests__ / index.node.js View on Github external
test('mock plugin', t => {
  t.equals(typeof mock.provides, 'function');
  const handlers = {test() {}};

  const appCreator = () => {
    const app = new App('content', el => el);
    app.register(RPCHandlersToken, handlers);
    return app;
  };

  const RPCRedux = getService(appCreator, mock);
  const mockCtx: Context = ({headers: {}, memoized: new Map()}: any);
  t.equal(typeof RPCRedux.from(mockCtx).request, 'function');
  t.end();
});
github fusionjs / fusionjs / fusion-plugin-react-redux / src / __tests__ / index.browser.js View on Github external
tape('browser with no preloadedState and no __REDUX_STATE__ element', t => {
  const Redux = GetReduxPlugin();
  const reducer = (state, action) => {
    return {
      ...state,
      test: action.payload || 1,
    };
  };
  const provider = getService(appCreator(reducer), Redux);
  const {store} = provider && provider.from();
  t.deepLooseEqual(store.getState(), {test: 1});
  store.dispatch({type: 'CHANGE', payload: 2});
  t.equals(store.getState().test, 2, 'state receives dispatch');
  t.end();
});
github fusionjs / fusionjs / create-fusion-plugin / templates / plugin / content / src / __tests__ / index.browser.js View on Github external
tape('browser provider', async t => {
  const reduxState = document.createElement('script');
  reduxState.setAttribute('type', 'application/json');
  reduxState.setAttribute('id', '__PLUGIN_VALUE__');
  reduxState.textContent = JSON.stringify({value: 'create-fusion-plugin'});
  document.body && document.body.appendChild(reduxState);
  const provider = getService(appCreator(), Plugin);
  const {value} = provider && provider.from();
  t.equal(value, 'create-fusion-plugin');
  t.end();
});
github fusionjs / fusionjs / fusion-plugin-rpc / src / __tests__ / index.node.js View on Github external
t.equal(payload.status, 'success');
      t.equal(typeof payload.timing, 'number');
    },
    from() {
      return this;
    },
  });

  const appCreator = () => {
    const app = new App('content', el => el);
    app.register(UniversalEventsToken, mockEmitter);
    app.register(RPCHandlersToken, mockHandlers);
    return app;
  };

  const rpcFactory = getService(appCreator, RPCPlugin);
  const rpc = rpcFactory.from(mockCtx);

  t.equals(typeof rpc.request, 'function', 'has request method');
  try {
    const p = rpc.request('test', 'test-args');
    t.ok(p instanceof Promise, 'has right return type');
    t.equals(await p, 1, 'method works');
  } catch (e) {
    t.fail(e);
  }
  t.end();
});
github fusionjs / fusionjs / fusion-plugin-react-redux / src / __tests__ / index.browser.js View on Github external
function getStore(appCreator, Redux) {
    const provider = getService(appCreator, Redux);
    return provider && provider.from().store;
  }
github fusionjs / fusionjs / fusion-plugin-react-redux / src / __tests__ / index.browser.js View on Github external
function getStore(appCreator, Redux) {
    const provider = getService(appCreator, Redux);
    return provider && provider.from().store;
  }

fusion-test-utils

Test utilities for FusionJS

MIT
Latest version published 1 year ago

Package Health Score

57 / 100
Full package analysis

Similar packages