0.0.1 • Published 4 years ago

act-master-test-utils v0.0.1

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

Act-Master-test-utils

ActTest - is a class that helps write tests for act-master.

ActTest - is a singleton class with static methods.

To write tests, use the method ActTest.getInstance(options?: ActMasterOptions).

It creates an instance of the act-master class, which can be easily used afterwards.

Example:

default configuration for examples
// Basic part, same for all examples

import { ActTest } from 'act-master-test-utils';

const $act = ActTest.getInstance();

beforeEach(() => {
  ActTest.resetAll();
});
// ...
// ... base settings

it('Example result', async () => {
  const action: ActMasterAction = {
    name: 'SomeName',
    exec() {
      return 42;
    }
  }

  $act.addActions([action]);

  await $act.exec('SomeName');

  expect(ActTest.getLastResult()).toBe(42);
});

You can also call some event and check your subscription.

// ... base settings

it('Example check subscription', async () => {
  const action: ActMasterAction = {
    name: 'SomeName',
    exec() {
      return 42;
    }
  }

  $act.addActions([action]);

  const mockFn = jest.fn();

  $act.subscribe('SomeName', mockFn);

  await ActTest.exec('SomeName');

  expect(mockFn).toBeCalledTimes(1);
});

List of available methods

Method NameDescription
getInstanceReturns the ActMaster instance
resetAllResets the ActMaster settings
getLastResultReturns the last value
addActionsAdds actions
execExecute action
subscribeSubscribes to action
entityCountReturns the number of entities ('actions' | 'waiters' | 'listeners' | 'di') *
removeSingletonRemoves singleton ActMaster *

* -Use if you know what it's for