Skip to content

Commit

Permalink
test(core): update aspectService.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Mar 29, 2023
1 parent 503009d commit 395adc2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/core/test/service/aspectService.test.ts
@@ -1,3 +1,5 @@
import { assert } from 'assert';

import { MidwayAspectService, MidwayContainer } from '../../src';

describe('/test/service/aspectService.test.ts', () => {
Expand Down Expand Up @@ -31,6 +33,7 @@ describe('/test/service/aspectService.test.ts', () => {
aspectService.interceptPrototypeMethod(A, 'invokeAsyncMethod', {
around: async (joinPoint) => {
console.log('before1');
assert(joinPoint.proceedIsAsyncFunction === true, 'proceedIsAsyncFunction should be true')
const result = await joinPoint.proceed(...joinPoint.args);
console.log('after1');
return result + ' midway 2.0';
Expand All @@ -40,6 +43,7 @@ describe('/test/service/aspectService.test.ts', () => {
aspectService.interceptPrototypeMethod(A, 'invokeAsyncMethod', {
around: async (joinPoint) => {
console.log('before2');
assert(joinPoint.proceedIsAsyncFunction === true, 'proceedIsAsyncFunction should be true')
const result = await joinPoint.proceed(...joinPoint.args);
console.log('after2');
return result + ' midway 3.0';
Expand All @@ -49,13 +53,15 @@ describe('/test/service/aspectService.test.ts', () => {
// test before
aspectService.interceptPrototypeMethod(A, 'invokeMethod', {
before: (joinPoint) => {
assert(joinPoint.proceedIsAsyncFunction === false, 'proceedIsAsyncFunction should be false')
joinPoint.args = [3, 4];
}
});

let err;
aspectService.interceptPrototypeMethod(A, 'gotError', {
afterThrow: (joinPoint, error) => {
assert(joinPoint.proceedIsAsyncFunction === false, 'proceedIsAsyncFunction should be false')
err = error;
}
});
Expand Down

0 comments on commit 395adc2

Please sign in to comment.