mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00

The previous package was outdated, preventing us from updating TS. This one also lints YAML and JSON, and applies many more rules to the test files, explaining all the changes in this PR.
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import type { ComponentsManager } from 'componentsjs';
|
|
import { BaseComponentsJsFactory } from '../../../../src/pods/generate/BaseComponentsJsFactory';
|
|
|
|
const manager: jest.Mocked<ComponentsManager<any>> = {
|
|
instantiate: jest.fn(async(): Promise<any> => 'store!'),
|
|
configRegistry: {
|
|
register: jest.fn(),
|
|
},
|
|
} as any;
|
|
|
|
jest.mock('componentsjs', (): any => ({
|
|
ComponentsManager: {
|
|
build: jest.fn(async(): Promise<ComponentsManager<any>> => manager),
|
|
},
|
|
}));
|
|
|
|
describe('A BaseComponentsJsFactory', (): void => {
|
|
let factory: BaseComponentsJsFactory;
|
|
const configPath = 'config!';
|
|
const componentIri = 'componentIri!';
|
|
const variables = {
|
|
aa: 'b',
|
|
cc: 'd',
|
|
};
|
|
|
|
beforeEach(async(): Promise<void> => {
|
|
jest.clearAllMocks();
|
|
factory = new BaseComponentsJsFactory();
|
|
});
|
|
|
|
it('calls Components.js with the given values.', async(): Promise<void> => {
|
|
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 });
|
|
});
|
|
});
|