refactor: update command tests to use require syntax and improve error handling
Deploy to NAS / deploy (push) Successful in 1m4s

This commit is contained in:
2025-12-25 10:28:44 -05:00
parent b362a43886
commit 06ac40a6d7
7 changed files with 33 additions and 25 deletions
+8 -8
View File
@@ -1,14 +1,16 @@
import { jest } from '@jest/globals';
const { createMockInteraction } = require('../utils/testUtils');
// Mock axios
jest.unstable_mockModule('axios', () => ({
jest.mock('axios', () => ({
__esModule: true,
default: {
post: jest.fn(),
},
}));
const axios = require('axios').default;
// Mock the discord.js module
jest.unstable_mockModule('discord.js', () => ({
// Mock discord.js
jest.mock('discord.js', () => ({
SlashCommandBuilder: jest.fn().mockReturnValue({
setName: jest.fn().mockReturnThis(),
setDescription: jest.fn().mockReturnThis(),
@@ -38,9 +40,7 @@ jest.unstable_mockModule('discord.js', () => ({
}),
}));
const axios = (await import('axios')).default;
const { createMockInteraction } = await import('../utils/testUtils.js');
const AskCommand = (await import('../../commands/ask.js')).default;
const AskCommand = require('../../commands/ask').default;
const askCommand = new AskCommand();
describe('Ask Command', () => {
@@ -258,4 +258,4 @@ describe('Ask Command', () => {
await expect(askCommand.run(interaction)).rejects.toThrow('Failed to follow up');
});
});
});
});