Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] 6.0.0 Dependency Inject dont work in Testingmodule override class #1689

Closed
12548 opened this issue Mar 17, 2019 · 5 comments
Closed

[bug] 6.0.0 Dependency Inject dont work in Testingmodule override class #1689

12548 opened this issue Mar 17, 2019 · 5 comments

Comments

@12548
Copy link

12548 commented Mar 17, 2019

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Minimal reproduction of the problem with instructions

demo code:

/* tslint:disable:max-classes-per-file */
import {Injectable} from '@nestjs/common'
import {Test} from '@nestjs/testing'

@Injectable()
class WorldService {

	get() {
		return 'world'
	}

}

@Injectable()
class HelloService {

	constructor(private readonly world: WorldService) {
	}

	hello() {
		console.log('hello ' + this.world.get())
	}

}

@Injectable()
class GoodbyeService {
	constructor(private readonly world: WorldService) {
	}

	hello() {
		console.log('goodbye ' + this.world.get())
	}

}

(async () => {
	const mod = await Test.createTestingModule({
		providers: [
			HelloService,
			WorldService,
		],
	})
		.overrideProvider(HelloService)
		.useClass(GoodbyeService)
		.compile()

	// should print 'goodbye world' but fails
	mod.get(HelloService).hello()

})()

Current behavior

the code fails with error:

(node:9176) UnhandledPromiseRejectionWarning: Error: Nest can't resolve dependencies of the HelloService (?). Please make sure that the argument at index [0] is available in the InternalCoreModule context.
    at Injector.lookupComponentInExports (C:\xxx\node_modules\@nestjs\core\injector\injector.js:180:19)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
(node:9176) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:9176) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Expected behavior

It works well in 5.7.4 and prints goodbye world.

Environment


Nest version: 6.0.0

 
For Tooling issues:
- Node version: 10.15.1
- Platform:  Windows

@12548 12548 changed the title 6.0.0 Dependency Inject dont work in Testingmodule override class. [bug] 6.0.0 Dependency Inject dont work in Testingmodule override class Mar 17, 2019
@kamilmysliwiec
Copy link
Member

Have you updated both @nestjs/core and @nestjs/testing packages? If so, we need a small repository which reproduces your issue.

@12548
Copy link
Author

12548 commented Mar 17, 2019

@kamilmysliwiec
Yes of course I upgraded them both.
I uploaded the small repo: https://github.com/12548/BugDemo1

@kamilmysliwiec
Copy link
Member

Thanks, I'll take a look :)

@kamilmysliwiec
Copy link
Member

It should be fixed in 6.0.1 :) Please, let me know if you encounter any issues.

@lock
Copy link

lock bot commented Sep 23, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants