loopbackio / loopbackio/loopback-next
Application works as expected, but unit tests fail in with 404 NotFoundError
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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