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: setProvide #2456

Closed
BBoehm opened this issue Jun 14, 2024 · 3 comments
Closed

Feature request: setProvide #2456

BBoehm opened this issue Jun 14, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@BBoehm
Copy link

BBoehm commented Jun 14, 2024

Is your feature request related to a problem? Please describe.
Testing different values for inject/provide currently needs a complete new wrapper to be defined:

  it('should do option A, if provided with "A"), () => {
    wrapper = shallowMount(VCommercialInfo, {
      props: myProps,
      global: {
        provide: {
          myProvide: ref('A'),
        },
      },
    });
    
    expect(...);
  });
  
  it('should do option B, if provided with "B"), () => {
    props: myProps,
    wrapper = shallowMount(VCommercialInfo, {
      global: {
        provide: {
          myProvide: ref('B'),
        },
      },
    });
    
    expect(...);
  });

This would get even more tedious when there is other data to be passed in, such as props/stubs/plugins/mocks/slots/... which would all lead to duplicate code.

Describe the solution you'd like
Would be great if we could have a setProvide function similar to setProps:

  it('should do option C, if provided with "C"), async () => {
    await wrapper.setProvide({
      myProvide: ref('C'),
    });
    
    expect(...);
  });
@lmiller1990
Copy link
Member

Could you could just create a function that reduces the duplication?

We used to have many things like setMethods, setComputed etc, the problem is the introduce something in your tests (changing the provided value) that cannot happen in a production environment. It led to many difficult to solve bugs, which is why setComputed does not exist anymore.

@lmiller1990 lmiller1990 added the enhancement New feature or request label Jun 26, 2024
@BBoehm
Copy link
Author

BBoehm commented Jul 26, 2024

Hi @lmiller1990,
thanks for the explanation. I was not aware of that, if those other functions were removed specifically, then it probably does not make sense to introduce this one - I will go for a local solution instead.

@BBoehm BBoehm closed this as completed Jul 26, 2024
@lmiller1990
Copy link
Member

Great, please share what you come up with!

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