loopbackio / loopbackio/loopback-next

Application works as expected, but unit tests fail in with 404 NotFoundError

Open
#9,819 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.1k
Forks
1.1k
Avg merge
2d 21h
Merged PRs (30d)
27

Description

Describe the bug

I created a simple application with lb4 cli, and it works fine when I run it. However, when I run a unit test, all controller, and repository tests fail. During the test, my application starts and the application init and start events both fire, and I successfully create a client using createRestAppClient. The home page works and so does the explorer page. However, the /ping route generates a 404 NotFoundError and the app.getRepository(MyRepository fails with MyRepositiry "is not bound to any value in context". What am I missing?

Logs
ResolutionError: The key 'repositories.MyRepository' is not bound to any value in context MyApplication-roGIIRWyRTi6GQlKUsHn_Q-0 (context: MyApplication-roGIIRWyRTi6GQlKUsHn_Q-0, binding: repositories.MyRepository)
Additional information

No response

Reproduction

Upcoming

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with the LoopBack CLI-generated application and its unit tests, focusing on createRestAppClient, the /ping route, and app.getRepository(MyRepository). Check the initialization logs and the reported repositories.MyRepository binding error; done means the controller and repository tests run without the 404 or unresolved repository error.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
api, backend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.