Skip to content

Commit 8f73925

Browse files
committed
fix test
1 parent bed1249 commit 8f73925

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tests/cli/initialize.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { describe, jest, test, afterEach } from '@jest/globals';
1+
import { describe, jest, test, afterEach, beforeEach } from '@jest/globals';
22
import { mockCommander, mockConfig } from '../mocks.js';
33

44
// setup mocks
55
mockCommander();
6-
mockConfig();
6+
const { getConfigValue } = mockConfig();
77
const actionChainMock = jest.fn();
88
jest.unstable_mockModule('src/actions/actionChainWithProgress.js', () => ({
99
createChainWithProgress: () => actionChainMock,
@@ -36,35 +36,44 @@ jest.unstable_mockModule('src/cli/auth.js', () => ({
3636

3737
// import after mocks set up.
3838
const { cwdIsEmpty } = await import('../../src/initialize/index.js');
39-
const { initializeAction } = await import('../../src/cli/initialize.js');
4039

4140
describe('initialize command', () => {
41+
beforeEach(() => {
42+
getConfigValue.mockImplementation((key) =>
43+
key === 'aoc.validation.years' ? [2001, 2002, 2003, 2004] : undefined
44+
);
45+
});
46+
4247
afterEach(() => {
4348
jest.resetAllMocks();
4449
});
4550

4651
test('does not ask for confirmation if cwd is empty', async () => {
52+
const { initializeAction } = await import('../../src/cli/initialize.js');
4753
cwdIsEmpty.mockResolvedValue(true);
4854
getAnswersFromUserMock.mockResolvedValue({ answers: {} });
4955
await initializeAction();
5056
expect(assertUserConfirmationMock).not.toHaveBeenCalled();
5157
});
5258

5359
test('asks for confirmation if cwd is not empty', async () => {
60+
const { initializeAction } = await import('../../src/cli/initialize.js');
5461
cwdIsEmpty.mockResolvedValue(false);
5562
assertUserConfirmationMock.mockResolvedValue(false);
5663
await initializeAction();
5764
expect(assertUserConfirmationMock).toHaveBeenCalled();
5865
});
5966

6067
test('aborts if user does not confirm', async () => {
68+
const { initializeAction } = await import('../../src/cli/initialize.js');
6169
cwdIsEmpty.mockResolvedValue(false);
6270
assertUserConfirmationMock.mockResolvedValue(false);
6371
await initializeAction();
6472
expect(actionChainMock).not.toHaveBeenCalled();
6573
});
6674

6775
test('continues if user confirms', async () => {
76+
const { initializeAction } = await import('../../src/cli/initialize.js');
6877
cwdIsEmpty.mockResolvedValue(false);
6978
assertUserConfirmationMock.mockResolvedValue(true);
7079
getAnswersFromUserMock.mockResolvedValue({ answers: {} });

0 commit comments

Comments
 (0)