forked from golevelup/nestjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b817f52
commit 2f8e195
Showing
13 changed files
with
99 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
examples/discovery/src/example/another/another.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AnotherService } from './another.service'; | ||
|
||
describe('AnotherService', () => { | ||
let service: AnotherService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [AnotherService], | ||
}).compile(); | ||
|
||
service = module.get<AnotherService>(AnotherService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class AnotherService {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./lib", | ||
"composite": true | ||
}, | ||
"include": ["./src"], | ||
"exclude": ["./src/**/*.spec.ts"], | ||
"references": [{ "path": "../common" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Injectable, Module, ReflectMetadata } from '@nestjs/common'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { | ||
DiscoveryModule, | ||
DiscoveryService, | ||
withMetaKey | ||
} from '../../src/discovery'; | ||
|
||
const TestConfigSymbol = Symbol('TestConfigSymbol'); | ||
|
||
const TestDecorator = (config: any) => | ||
ReflectMetadata(TestConfigSymbol, config); | ||
|
||
@Injectable() | ||
@TestDecorator('42') | ||
class ExampleService { | ||
doSomething() { | ||
console.log('doing something'); | ||
} | ||
} | ||
|
||
@Module({ | ||
providers: [ExampleService] | ||
}) | ||
class ExampleModule {} | ||
|
||
describe('Discovery', () => { | ||
let app: TestingModule; | ||
|
||
beforeEach(async () => { | ||
app = await Test.createTestingModule({ | ||
imports: [DiscoveryModule, ExampleModule] | ||
}).compile(); | ||
|
||
await app.init(); | ||
}); | ||
|
||
it('should discover providers based on metadata', () => { | ||
const discoveryService = app.get<DiscoveryService>(DiscoveryService); | ||
const testProviders = discoveryService.discoverClasses(x => | ||
withMetaKey(TestConfigSymbol, x) | ||
); | ||
|
||
expect(testProviders).toHaveLength(1); | ||
console.log(testProviders[0].instance); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./lib", | ||
"composite": true | ||
}, | ||
"exclude": ["./src/**/*.spec.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ | |
"@nestjs-plus/*": ["./*/src"] | ||
} | ||
}, | ||
"exclude": ["node_modules", "**/*.spec.ts"] | ||
"exclude": ["node_modules"] | ||
} |