edge
edge copied to clipboard
Question - How to test `EdgeRenderer#share`
Say I have some middleware like:
import type { HttpContext } from '@adonisjs/core/http'
import type { NextFn } from '@adonisjs/core/types/http'
export default class ViewDataMiddleware {
async handle(ctx: HttpContext, next: NextFn) {
ctx.view.share({
something: 'to test'
})
return await next()
}
}
How can I do assertions to check that data was indeed shared with the view?
My use case here is that I've a bunch of data for every view (like site name and summary, and these appear on all pages, so loading them in middleware and then sharing that way felt cleaner, but I don't actually need to load them when I do content-negotiation to json, only for html, so I'd like to assert that's the case.
This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue
I think if you write a unit test just for the middleware, then you could test it with a fake instance of HTTP context right?
However, we will have to add a renderer.getState() method that should return the globals and the locals of an Edge renderer. Happy to accept a PR for the same
This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue
This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue
This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue
This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue
I think if you write a unit test just for the middleware, then you could test it with a fake instance of HTTP context right?
However, we will have to add a
renderer.getState()method that should return theglobalsand thelocalsof an Edge renderer. Happy to accept a PR for the same
@thetutlage have opened https://github.com/edge-js/edge/pull/167 which should implement this as described.
Released https://github.com/edge-js/edge/releases/tag/v6.3.0