Tuleap 16 est là ! Assistez à l'événement virtuel le 17 octobre à 10h30. Inscrivez-vous ici !

    •  
      request #38693 Use vue/test-utils instead of mocking strict inject
    Infos
    #38693
    Joris MASSON (jmasson)
    2024-07-19 16:18
    2024-07-16 15:01
    40307
    Details
    Use vue/test-utils instead of mocking strict inject

    When using provide/inject, we are currently mocking @tuleap/strict-inject in every test. @vue/test-utils can help us: by leveraging its configuration, we can inject just like in production, which makes mocking unnecessary.

    // Stop doing this:
    vi.mock("@tuleap/vue-strict-inject");
    
    vi.spyOn(strict_inject, "strictInject").mockImplementation((key) => {
      switch (key) {
        case MY_INJECTION:
          return 123;
        case MY_OTHER_INJECTION:
          return "abc";
      }
    });
    
    // Do this instead:
    function getWrapper(): VueWrapper {
        return shallowMount(MyComponent, {
          global: {
            provide: {
              [MY_INJECTION.valueOf()]: 123,
              [MY_OTHER_INJECTION.valueOf()]: "abc",
            },
          },
      });
    }
    
    Dev tools
    Empty
    Empty
    • [ ] enhancement
    • [ ] internal improvement
    Empty
    Stage
    Joris MASSON (jmasson)
    Closed
    2024-07-19
    Attachments
    Empty
    References

    Follow-ups