Commit c0ed61e6 authored by nanahira's avatar nanahira

add more unit tests

parent b276ec6b
Pipeline #14633 failed with stages
in 1 minute and 10 seconds
......@@ -56,12 +56,13 @@ export class RegistrarAspect<Ctx extends Context, T = any> {
): Registrar.RegisterResult<Ctx, T> {
const data = this.registrar.reflector.get('CordisRegister', this.obj, key);
if (!data) return;
const specificCtx = this.getScopeContext(ctx, key, extraView, false);
const result = data.action(
this.getScopeContext(ctx, key, extraView, false),
specificCtx,
extractObjectMethod(this.obj, key),
...renderObject(data.args, { ...this.view, ...extraView }),
);
return { ...data, key: key, result };
return { ...data, key: key, result, ctx: specificCtx };
}
private registerWithLoopControl(
......
......@@ -79,6 +79,7 @@ export namespace Registrar {
> extends RegisterInfo<C> {
key: keyof T & string;
result: MethodReturn<C, K>;
ctx: C;
}
export interface ProvideOptions extends Context.ServiceOptions {
......
import { DefinePlugin, StarterPlugin, UseEvent } from './utility/decorators';
import { Provide, UsingService } from '../src/decorators';
import { Context } from 'cordis';
declare module 'cordis' {
interface Events<C> {
foo(): string;
}
}
@Provide('foo')
@DefinePlugin()
class MyProvider extends StarterPlugin() {}
@DefinePlugin()
class MyPlugin extends StarterPlugin() {
@UsingService('foo')
@UseEvent('foo')
onFoo() {
return 'bar';
}
}
describe('Partial using service', () => {
it('should trigger when available', async () => {
const app = new Context();
await app.start();
app.plugin(MyPlugin);
expect(app.bail('foo')).toBeUndefined();
const state = app.plugin(MyProvider);
expect(app.bail('foo')).toBe('bar');
state.dispose();
expect(app.bail('foo')).toBeUndefined();
app.plugin(MyProvider);
expect(app.bail('foo')).toBe('bar');
});
});
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