Commit f95469e6 authored by nanahira's avatar nanahira

tests

parent 4a46240e
......@@ -47,7 +47,7 @@ export namespace CommandPut {
preRegistry.extend('arg', (data, cmd, ctx, nativeType) => {
let arg = cmd._arguments[data.index];
if (arg) {
if (!arg) {
arg = {};
cmd._arguments[data.index] = arg;
}
......
import {
CommandUsage,
PutArg,
PutOption,
UseCommand,
UseEvent,
UseMiddleware,
} from '../src/decorators/decorators';
} from '../src/decorators';
import { App, Command, Next, Session } from 'koishi';
import { Registrar } from '../src/register';
import { EventNameAndPrepend } from '../src/def';
......@@ -30,6 +31,11 @@ class MyClass {
async onEcho(@PutOption('content', '-c <content>') content: string) {
return `bot: ${content}`;
}
@UseCommand('count')
async onCount(@PutArg(0) count: number) {
return `I have ${count} dresses.`;
}
}
const registrar = new Registrar(new MyClass());
......@@ -54,7 +60,7 @@ describe('Register', () => {
expect((result.data as EventNameAndPrepend).name).toBe('message');
});
it('should register command', () => {
it('should register command and infer option type', () => {
const result = registrar.register(app, 'onEcho');
expect(result.type).toBe('command');
const command: Command = result.result;
......@@ -65,4 +71,12 @@ describe('Register', () => {
'bot: hello',
);
});
it('should infer argument type', () => {
const result = registrar.register(app, 'onCount');
expect(result.type).toBe('command');
const command: Command = result.result;
expect(command._arguments[0].type).toBe('number');
expect(command.execute({ args: ['4'] })).resolves.toBe('I have 4 dresses.');
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment