Categories hapi

19 posts

Auto Added by WPeMatico

hapi โ€” Inject Request Payload, Headers and Parameters While Testing Route Handlers

Testing in hapi builds on top of a single method: server.inject. Injecting requests is a core element in testing your hapi app. A previous tutorial walked you through the basics of injecting requests to test route handlers. What we didnโ€™t cover there is the ability to inject requests with payload, […]

๐ŸŒŸ learn hapi โ€” Update Mongoose Models for JSON Responses

While creating the Futureflix API, you noticed that the JSON representation of documents contains the _id and version key __v. The _id field feels wrong due to the underscore prefix, so letโ€™s remove it and keep only the id field. The version key __v isnโ€™t necessary in the response at […]

hapi โ€” Test Route Handlers by Injecting Requests

One of the reasons weโ€™re passionate about hapi is its easiness of testing. The framework has a built-in server.inject method that simulates an incoming HTTP request. A server.inject call wonโ€™t create a socket connection. Youโ€™re not relying to the network stack to run tests in your app. That means, testing […]

hapi โ€” Run Tests with Assertions using Code

Testing your hapi applications might require expected values and responses that match a set of data. The code library from hapiโ€™s ecosystem is an assertions library based on chai. Code exposes an expressive and readable language-style interface. Youโ€™ll get a grasp on features and the usage in the upcoming sections. […]