import type { ComponentsManager } from 'componentsjs'; import { BaseComponentsJsFactory } from '../../../../src/pods/generate/BaseComponentsJsFactory'; const manager: jest.Mocked> = { instantiate: jest.fn(async(): Promise => 'store!'), configRegistry: { register: jest.fn(), }, } as any; jest.mock('componentsjs', (): any => ({ // eslint-disable-next-line @typescript-eslint/naming-convention ComponentsManager: { build: jest.fn(async(): Promise> => manager), }, })); describe('A BaseComponentsJsFactory', (): void => { let factory: BaseComponentsJsFactory; const configPath = 'config!'; const componentIri = 'componentIri!'; const variables = { aa: 'b', cc: 'd', }; beforeEach(async(): Promise => { jest.clearAllMocks(); factory = new BaseComponentsJsFactory(); }); it('calls Components.js with the given values.', async(): Promise => { await expect(factory.generate(configPath, componentIri, variables)).resolves.toBe('store!'); expect(manager.configRegistry.register).toHaveBeenCalledTimes(1); expect(manager.configRegistry.register).toHaveBeenLastCalledWith(configPath); expect(manager.instantiate).toHaveBeenCalledTimes(1); expect(manager.instantiate).toHaveBeenLastCalledWith(componentIri, { variables }); }); });