Skip to content

Commit 3bc528c

Browse files
author
Shady Khalifa
authored
Merge pull request #19 from nestjs-community/fix/for-async-promise
Added promise type to async forRootAsync
2 parents 5bba217 + 1ac6d68 commit 3bc528c

File tree

3 files changed

+1341
-1128
lines changed

3 files changed

+1341
-1128
lines changed

src/access-control.module.async.spec.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import {AccessControlModule} from './access-control.module';
22
import {Test, TestingModule} from '@nestjs/testing';
33
import { RolesBuilder } from './roles-builder.class';
44
import {ROLES_BUILDER_TOKEN} from './constants';
5+
import { delay } from 'rxjs/operators';
56

67
describe('forRootAsync', () => {
7-
it('Can instance with asnyc provider method', async () => {
8+
it('Can instance with provider method', async () => {
89

910
const module: TestingModule = await Test.createTestingModule({
1011
imports: [
@@ -18,4 +19,22 @@ describe('forRootAsync', () => {
1819

1920
expect(roles).toBeInstanceOf(RolesBuilder);
2021
});
22+
23+
it('Can instance with asnyc provider method', async () => {
24+
25+
const module: TestingModule = await Test.createTestingModule({
26+
imports: [
27+
AccessControlModule.forRootAsync({
28+
useFactory: async (): Promise<RolesBuilder> => {
29+
await delay(100);
30+
return new RolesBuilder();
31+
},
32+
}),
33+
],
34+
}).compile();
35+
36+
const roles = module.get(ROLES_BUILDER_TOKEN);
37+
38+
expect(roles).toBeInstanceOf(RolesBuilder);
39+
});
2140
});

src/access-control.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class AccessControlModule {
3030

3131
public static forRootAsync(options: {
3232
inject?: Provider[],
33-
useFactory: (...args: any) => RolesBuilder,
33+
useFactory: (...args: any) => RolesBuilder | Promise<RolesBuilder>,
3434
}): DynamicModule {
3535

3636
const provider = {

0 commit comments

Comments
 (0)