Skip to content

test(core): add unit tests for module-ref - #17401

Open
Se3do wants to merge 1 commit into
nestjs:masterfrom
Se3do:test/module-ref-unit-tests
Open

test(core): add unit tests for module-ref#17401
Se3do wants to merge 1 commit into
nestjs:masterfrom
Se3do:test/module-ref-unit-tests

Conversation

@Se3do

@Se3do Se3do commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe: Tests

What is the current behavior?

ModuleRef (in packages/core/injector/module-ref.ts) has zero dedicated unit tests. Its methods (introspect, registerRequestByContextId, instantiateClass, find, resolve) are only covered indirectly through NestApplicationContext integration tests.

Issue Number: N/A

What is the new behavior?

Adds packages/core/test/injector/module-ref.spec.ts with 12 tests covering:

  • introspect() — returns correct scope for DEFAULT, REQUEST, and TRANSIENT providers
  • registerRequestByContextId() — delegates to container
  • instantiateClass() — resolves dependencies and propagates errors
  • find() — single lookup, request-scoped rejection, multi-instance with each: true
  • resolve() — static, transient (unique per context), and request-scoped resolution

All existing tests continue to pass.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Covers:
- introspect() for DEFAULT, REQUEST, and TRANSIENT scopes
- registerRequestByContextId() delegation
- instantiateClass() with dependency resolution and error propagation
- find() for single, request-scoped, and multi-instance lookups
- resolve() for static, transient (unique per context), and
  request-scoped providers
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 0

Coverage increased (+0.01%) to 90.317%

Details

  • Coverage increased (+0.01%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 8665
Covered Lines: 7826
Line Coverage: 90.32%
Relevant Branches: 2955
Covered Branches: 2413
Branch Coverage: 81.66%
Branches in Coverage %: No
Coverage Strength: 57.87 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants