Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add support for app.runWithContext() #2059

Closed
posva opened this issue May 17, 2023 · 3 comments
Closed

Feature request: Add support for app.runWithContext() #2059

posva opened this issue May 17, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@posva
Copy link
Member

posva commented May 17, 2023

This feature was introduced here and it's now used by vue router and pinia. Adding this will help people use the new feature

Here is a currently failing test using only vue test utils

  it('runWithContext', () => {
    let app: App
    const wrapper = mount(
      {
        template: `<HasInjection />`,
        setup() {
          provide('hello', 'component')
          return {}
        },
        components: {
          HasInjection: {
            setup() {
              const globalInjection = app!.runWithContext(() =>
                inject('hello', 'fallback')
              )
              const parentInjection = inject('hello', 'fallback')
              return { parentInjection, globalInjection }
            },
            template: `<div>{{ parentInjection }};{{ globalInjection }}</div>`,
          },
        },
      },
      {
        global: {
          provide: {
            hello: 'global',
          },
          plugins: [
            (a) => {
              app = a
            },
          ],
        },
      }
    )

    expect(wrapper.text()).toBe('component;global')
  })
@posva posva added the enhancement New feature or request label May 17, 2023
@posva
Copy link
Member Author

posva commented May 17, 2023

I added the failing test at https://github.com/vuejs/test-utils/tree/feat/runWithContext in case anybody wants to pick up the task

@cexbrayat
Copy link
Member

I'm not yet familiar with this feature you implemented in core, but looking at
vuejs/core@869f3fb#diff-aba22e928f34a9ced3bf916c54a41b6facdfcb3e2caa18534dfae6d8a7e3cea6R56-R60
I thought this was expected if runWIthContext is in a component.

As instance will not be null, no? And in that case, the current app context will not be checked.
Or am I missing something obvious?

@posva
Copy link
Member Author

posva commented May 18, 2023

I'm getting a different behavior within pinia but apparently it's the normal behavior. I think I must be forgetting something though. I wonder if it wouldn't be more consistent to give preference to the app within runWithContext, but that's a core thing anyway. Sorry 😅

@posva posva closed this as not planned Won't fix, can't repro, duplicate, stale May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants