Initial commit
Some checks failed
Some checks failed
This commit is contained in:
33
__tests__/main.test.ts
Normal file
33
__tests__/main.test.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Unit tests for the action's main functionality, src/main.ts
|
||||
*
|
||||
* To mock dependencies in ESM, you can create fixtures that export mock
|
||||
* functions and objects. For example, the core module is mocked in this test,
|
||||
* so that the actual '@actions/core' module is not imported.
|
||||
*/
|
||||
import { jest } from '@jest/globals';
|
||||
import * as core from '../__fixtures__/core.js';
|
||||
|
||||
// Mocks should be declared before the module being tested is imported.
|
||||
jest.unstable_mockModule('@actions/core', () => core);
|
||||
|
||||
// The module being tested should be imported dynamically. This ensures that the
|
||||
// mocks are used in place of any actual dependencies.
|
||||
const { run } = await import('../src/main.js');
|
||||
|
||||
describe('main.ts', () => {
|
||||
beforeEach(() => {
|
||||
// Set the action's inputs as return values from core.getInput().
|
||||
core.getInput.mockImplementation(() => '500');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks();
|
||||
});
|
||||
|
||||
it('Reads only one input', async () => {
|
||||
await run();
|
||||
|
||||
expect(core.getInput).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user