fix: api tests

This commit is contained in:
hypercross 2026-04-06 11:12:20 +08:00
parent b3ff589aa5
commit 1e7dbea129
1 changed files with 10 additions and 10 deletions

View File

@ -277,7 +277,7 @@ describe('prompt', () => {
const chooseRunner: CommandRunner<TestContext, string> = { const chooseRunner: CommandRunner<TestContext, string> = {
schema: parseCommandSchema('choose'), schema: parseCommandSchema('choose'),
run: async function () { run: async function () {
const result = await this.prompt('select <card>', (cmd) => cmd.params[0] as string); const result = await this.prompt('select <card>', (card) => card as string);
this.context.log.push(`selected ${result}`); this.context.log.push(`selected ${result}`);
return result; return result;
}, },
@ -317,7 +317,7 @@ describe('prompt', () => {
schema: parseCommandSchema('choose'), schema: parseCommandSchema('choose'),
run: async function () { run: async function () {
try { try {
await this.prompt('select <card>', (cmd) => cmd.params[0] as string); await this.prompt('select <card>', (card) => card as string);
return 'unexpected success'; return 'unexpected success';
} catch (e) { } catch (e) {
return (e as Error).message; return (e as Error).message;
@ -356,7 +356,7 @@ describe('prompt', () => {
const pickRunner: CommandRunner<TestContext, string> = { const pickRunner: CommandRunner<TestContext, string> = {
schema: parseCommandSchema('pick'), schema: parseCommandSchema('pick'),
run: async function () { run: async function () {
const result = await this.prompt(schema, (cmd) => cmd.params[0] as string); const result = await this.prompt(schema, (item) => item as string);
return result; return result;
}, },
}; };
@ -393,8 +393,8 @@ describe('prompt', () => {
const multiPromptRunner: CommandRunner<TestContext, string[]> = { const multiPromptRunner: CommandRunner<TestContext, string[]> = {
schema: parseCommandSchema('multi'), schema: parseCommandSchema('multi'),
run: async function () { run: async function () {
const first = await this.prompt('first <a>', (cmd) => cmd.params[0] as string); const first = await this.prompt('first <a>', (a) => a as string);
const second = await this.prompt('second <b>', (cmd) => cmd.params[0] as string); const second = await this.prompt('second <b>', (b) => b as string);
return [first, second]; return [first, second];
}, },
}; };
@ -440,12 +440,12 @@ describe('prompt', () => {
run: async function () { run: async function () {
const result = await this.prompt( const result = await this.prompt(
'select <card>', 'select <card>',
(cmd) => { (card) => {
const card = cmd.params[0] as string; const cardStr = card as string;
if (!['Ace', 'King', 'Queen'].includes(card)) { if (!['Ace', 'King', 'Queen'].includes(cardStr)) {
throw `Invalid card: ${card}. Must be Ace, King, or Queen.`; throw `Invalid card: ${cardStr}. Must be Ace, King, or Queen.`;
} }
return card; return cardStr;
} }
); );
return result; return result;