3.39.3 • Published 23 days ago

@eggjs/tegg-eventbus-plugin v3.39.3

Weekly downloads
-
License
-
Repository
github
Last release
23 days ago

@eggjs/tegg-eventbus-plugin

Usage

// plugin.js
export.eventbusModule = {
  enable: true,
  package: '@eggjs/tegg-eventbus-plugin',
};

Unittest

// test/fixtures/apps/event-app/app/event-module/HelloService
@ContextProto({
  accessLevel: AccessLevel.PUBLIC,
})
export class HelloService {
  @Inject()
  private readonly eventBus: EventBus;

  hello() {
    this.eventBus.emit('hello', '01');
  }
}

// test/fixtures/apps/event-app/app/event-module/HelloLogger
@Event('helloEgg')
export class HelloLogger {
  handle(msg: string) {
    console.log('hello, ', msg);
  }
}


// test/event.test.ts
import assert from 'assert';
import path from 'path';
import mm from 'egg-mock';
import { HelloService } from './fixtures/apps/event-app/app/event-module/HelloService';
import { HelloLogger } from './fixtures/apps/event-app/app/event-module/HelloLogger';

describe('test/eventbus.test.ts', () => {
  let app;
  let ctx;

  afterEach(async () => {
    await app.destroyModuleContext(ctx);
    mm.restore();
  });

  before(async () => {
    app = mm.app();
    await app.ready();
  });

  after(() => {
    return app.close();
  });

  it('msg should work', async () => {
    ctx = await app.mockModuleContext();
    const helloService = await ctx.getEggObject(HelloService);
    let msg: string | undefined;
    // helloLogger is in child context, should mock the prototype
    mm(HelloLogger.prototype, 'handle', m => {
      msg = m;
    });
    const eventWaiter = await app.getEventWaiter();
    const helloEvent = eventWaiter.await('hello');
    helloService.hello();
    await helloEvent;
    assert(msg === '01');
  });
});
3.39.1

23 days ago

3.39.2

23 days ago

3.39.3

23 days ago

3.38.0

1 month ago

3.39.0

1 month ago

3.37.3

1 month ago

3.37.0

1 month ago

3.37.1

1 month ago

3.36.3

1 month ago

3.36.2

1 month ago

3.36.1

1 month ago

3.36.0

2 months ago

3.35.0

2 months ago

3.35.1

2 months ago

3.33.0

2 months ago

3.33.1

2 months ago

3.34.0

2 months ago

3.32.0

3 months ago

3.31.0

4 months ago

3.30.1

4 months ago

3.30.0

4 months ago

3.29.0

5 months ago

3.28.2

5 months ago

3.28.1

5 months ago

3.28.0

5 months ago

3.20.0

9 months ago

3.22.0

8 months ago

3.15.0

9 months ago

3.17.0

9 months ago

3.19.0

9 months ago

3.12.0

10 months ago

3.26.0

6 months ago

3.21.0

8 months ago

3.23.0

8 months ago

3.14.1

9 months ago

3.14.0

10 months ago

3.14.3

9 months ago

3.16.0

9 months ago

3.14.2

9 months ago

3.18.1

9 months ago

3.18.0

9 months ago

3.14.4

9 months ago

3.13.0

10 months ago

3.25.1

7 months ago

3.27.0

6 months ago

3.25.2

7 months ago

3.10.0

11 months ago

3.11.0

11 months ago

3.11.1

11 months ago

3.9.0

11 months ago

3.8.0

12 months ago

3.6.2

1 year ago

3.6.1

1 year ago

3.6.0

1 year ago

1.5.6

1 year ago

3.6.3

1 year ago

3.7.0

1 year ago

3.5.2

1 year ago

3.5.1

1 year ago

3.5.0

1 year ago

3.0.0-alpha.0

1 year ago

3.4.0

1 year ago

3.2.2

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.2.4

1 year ago

3.4.1

1 year ago

3.2.3

1 year ago

3.0.0

1 year ago

1.5.5

1 year ago

1.5.4

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

3.3.1

1 year ago

3.3.0

1 year ago

3.1.0

1 year ago

3.3.4

1 year ago

3.3.3

1 year ago

3.3.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.9

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.3.8

2 years ago

1.0.5

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.2.0

2 years ago

0.1.17

2 years ago

0.1.18

2 years ago

0.1.19

2 years ago

0.1.16

2 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.10

3 years ago

0.1.8

3 years ago

0.1.9

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago