Skip to content

Commit

Permalink
test(Cron): Add test to Cron node
Browse files Browse the repository at this point in the history
  • Loading branch information
dana-gill committed Dec 27, 2024
1 parent 983e87a commit 01799ce
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/nodes-base/nodes/Cron/test/Cron.node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { mock } from 'jest-mock-extended';
import { get } from 'lodash';
import {
type ITriggerFunctions,
type INodeExecutionData,
type IDataObject,
type IGetNodeParameterOptions,
} from 'n8n-workflow';

import { Cron } from '../Cron.node';

describe('Cron Node', () => {
const node = new Cron();

const createMockExecuteFunction = (nodeParameters: IDataObject) => {
const fakeExecuteFunction = {
getNodeParameter(
parameterName: string,
fallbackValue?: IDataObject | undefined,
options?: IGetNodeParameterOptions | undefined,
) {
const parameter = options?.extractValue ? `${parameterName}.value` : parameterName;

const parameterValue = get(nodeParameters, parameter, fallbackValue);

return parameterValue;
},
} as unknown as ITriggerFunctions;
return fakeExecuteFunction;
};

const triggerFunctions = createMockExecuteFunction({
triggerTimes: {
item: [],
},
});

afterAll(() => {
jest.resetAllMocks();
});

it('should return a function to trigger', async () => {
expect(await node.trigger.call(triggerFunctions)).toEqual({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
manualTriggerFunction: expect.any(Function),
});
});
});

0 comments on commit 01799ce

Please sign in to comment.