Skip to content

Commit

Permalink
Verifies that input parameters are correctly parsed
Browse files Browse the repository at this point in the history
Since jest doesn't support argument constraints on stubs
(see jestjs/jest#6180), we use the 'jest-when' library
to fake that certain input arguments are passed to the action
by specifying that the 'core.getInput' function should return
certain values when invoked with specific parameter names.
  • Loading branch information
ecampidoglio committed Nov 1, 2019
1 parent 70405df commit 812cb42
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@actions/core';
import { when } from 'jest-when';
import { run } from '../src/main';
import { ToolsDirectory } from '../src/toolsDirectory';
import { DotNet } from '../src/dotnet';
Expand Down Expand Up @@ -41,12 +42,11 @@ describe('When running the action with the script path input argument', () => {
const fakeCakeTool = CakeTool as jest.MockedClass<typeof CakeTool>;

beforeAll(() => {
fakeGetInput.mockReturnValue('path/to/script.cake');
when(fakeGetInput).calledWith('script-path').mockReturnValue('path/to/script.cake');
});

test('it should run the specified Cake script', async () => {
await run();
expect(fakeGetInput).toBeCalledWith('script-path');
expect(fakeCakeTool.runScript).toBeCalledWith(
'path/to/script.cake',
expect.anything(),
Expand All @@ -59,12 +59,11 @@ describe('When running the action with the target input argument', () => {
const fakeCakeTool = CakeTool as jest.MockedClass<typeof CakeTool>;

beforeAll(() => {
fakeGetInput.mockReturnValue('Task-To-Run');
when(fakeGetInput).calledWith('target').mockReturnValue('Task-To-Run');
});

test('it should run the specified Cake script', async () => {
await run();
expect(fakeGetInput).toBeCalledWith('target');
expect(fakeCakeTool.runScript).toBeCalledWith(
expect.anything(),
expect.anything(),
Expand Down

0 comments on commit 812cb42

Please sign in to comment.