edge icon indicating copy to clipboard operation
edge copied to clipboard

Question - How to test `EdgeRenderer#share`

Open ThisIsMissEm opened this issue 8 months ago • 5 comments
trafficstars

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.

ThisIsMissEm avatar Mar 22 '25 17:03 ThisIsMissEm

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

github-actions[bot] avatar Apr 13 '25 03:04 github-actions[bot]

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

thetutlage avatar Apr 14 '25 06:04 thetutlage

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

github-actions[bot] avatar May 06 '25 02:05 github-actions[bot]

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

github-actions[bot] avatar May 28 '25 02:05 github-actions[bot]

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

github-actions[bot] avatar Jun 19 '25 02:06 github-actions[bot]

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

github-actions[bot] avatar Jul 11 '25 02:07 github-actions[bot]

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

@thetutlage have opened https://github.com/edge-js/edge/pull/167 which should implement this as described.

ThisIsMissEm avatar Jul 20 '25 17:07 ThisIsMissEm

Released https://github.com/edge-js/edge/releases/tag/v6.3.0

thetutlage avatar Jul 21 '25 05:07 thetutlage