fix: fix tests
This commit is contained in:
@@ -246,8 +246,8 @@ describe('prompt', () => {
|
||||
const chooseRunner: CommandRunner<TestContext, string> = {
|
||||
schema: parseCommandSchema('choose'),
|
||||
run: async function () {
|
||||
const result = await this.prompt('select <card>');
|
||||
return result.params[0] as string;
|
||||
const result = await this.prompt('select <card>', (cmd) => cmd.params[0] as string);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -266,6 +266,9 @@ describe('prompt', () => {
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
expect(promptEvent).not.toBeNull();
|
||||
expect(promptEvent!.schema.name).toBe('select');
|
||||
|
||||
promptEvent!.cancel('test cleanup');
|
||||
await runPromise;
|
||||
});
|
||||
|
||||
it('should resolve prompt with valid input', async () => {
|
||||
@@ -274,9 +277,9 @@ describe('prompt', () => {
|
||||
const chooseRunner: CommandRunner<TestContext, string> = {
|
||||
schema: parseCommandSchema('choose'),
|
||||
run: async function () {
|
||||
const result = await this.prompt('select <card>');
|
||||
this.context.log.push(`selected ${result.params[0]}`);
|
||||
return result.params[0] as string;
|
||||
const result = await this.prompt('select <card>', (cmd) => cmd.params[0] as string);
|
||||
this.context.log.push(`selected ${result}`);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -314,7 +317,7 @@ describe('prompt', () => {
|
||||
schema: parseCommandSchema('choose'),
|
||||
run: async function () {
|
||||
try {
|
||||
await this.prompt('select <card>');
|
||||
await this.prompt('select <card>', (cmd) => cmd.params[0] as string);
|
||||
return 'unexpected success';
|
||||
} catch (e) {
|
||||
return (e as Error).message;
|
||||
@@ -353,8 +356,8 @@ describe('prompt', () => {
|
||||
const pickRunner: CommandRunner<TestContext, string> = {
|
||||
schema: parseCommandSchema('pick'),
|
||||
run: async function () {
|
||||
const result = await this.prompt(schema);
|
||||
return result.params[0] as string;
|
||||
const result = await this.prompt(schema, (cmd) => cmd.params[0] as string);
|
||||
return result;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -390,9 +393,9 @@ describe('prompt', () => {
|
||||
const multiPromptRunner: CommandRunner<TestContext, string[]> = {
|
||||
schema: parseCommandSchema('multi'),
|
||||
run: async function () {
|
||||
const first = await this.prompt('first <a>');
|
||||
const second = await this.prompt('second <b>');
|
||||
return [first.params[0] as string, second.params[0] as string];
|
||||
const first = await this.prompt('first <a>', (cmd) => cmd.params[0] as string);
|
||||
const second = await this.prompt('second <b>', (cmd) => cmd.params[0] as string);
|
||||
return [first, second];
|
||||
},
|
||||
};
|
||||
|
||||
@@ -440,12 +443,12 @@ describe('prompt', () => {
|
||||
(cmd) => {
|
||||
const card = cmd.params[0] as string;
|
||||
if (!['Ace', 'King', 'Queen'].includes(card)) {
|
||||
return `Invalid card: ${card}. Must be Ace, King, or Queen.`;
|
||||
throw `Invalid card: ${card}. Must be Ace, King, or Queen.`;
|
||||
}
|
||||
return null;
|
||||
return card;
|
||||
}
|
||||
);
|
||||
return result.params[0] as string;
|
||||
return result;
|
||||
},
|
||||
};
|
||||
|
||||
@@ -486,7 +489,7 @@ describe('prompt', () => {
|
||||
schema: parseCommandSchema('choose'),
|
||||
run: async function () {
|
||||
try {
|
||||
await this.prompt('select <card>');
|
||||
await this.prompt('select <card>', (cmd) => cmd.params[0] as string);
|
||||
return 'unexpected success';
|
||||
} catch (e) {
|
||||
return (e as Error).message;
|
||||
|
||||
Reference in New Issue
Block a user