docs.nestjs.com
docs.nestjs.com copied to clipboard
Documenting how to pass options to createNestApplication in tests
I'm submitting a...
- [ ] Regression
- [ ] Bug report
- [ ] Feature request
- [x] Documentation issue or request (new chapter/page)
- [ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
As you can see if you search "nest bodyparser" or "nest webhook" on google, a lot of people struggle with the process of removing default json parsing, and using custom middlewares. I think there is enough help online to do that, but I haven't found anything about e2e testing the webhook.
The problem I encountered was finding how to pass the { bodyParser: false } option to the test application.
On the normal application, the code is:
NestFactory.create(AppModule, { bodyParser: false });
But I couldn't find anything about how to do this on the test application.
Expected behavior
After digging through the code, I found out that the way to do it was :
app = moduleFixture.createNestApplication(undefined, { bodyParser: false });
This is not obvious at all, and a simple line in the doc explaining how to pass options as the second argument to the test application factory would have been great. I think this shoud go in the End-to-end section of https://github.com/nestjs/docs.nestjs.com/blob/master/content/fundamentals/unit-testing.md
Thank you very much for your work and the amazing framework!
in v9 you can use app = moduleFixture.createNestApplication({ bodyParser: false }); which is intuitive.
so I believe there's no need to document that in the docs website anymore.
I guess we can close this now :smiley_cat: unless you think we need to update v8 docs
hi @silto do you think that we should update v8 docs?
I'm sorry this got lost in my notifications. I suppose updating v8 docs would be a good idea since a lot of people are probably still using it, but this is not my repo so do as you see fit I guess 😉
since I didn't saw people asking about that so far, I won't update v8 docs to add this hint myself.
So yeah, it's all up to you now haha feel free to open a PR.