histoire icon indicating copy to clipboard operation
histoire copied to clipboard

feat(plugin-nuxt): mock useNuxtApp

Open filiphazardous opened this issue 6 months ago • 6 comments

Description

This PR introduces the ability to mock, keeping, or exclude parts of the nuxtApp object, as returned from the useNuxtApp composable.

Additional context

A number of tools used in Nuxt components rely on data passed through the nuxtApp object. Among them are @nuxtjs/i18n and @nuxtjs/apollo. For the i18n scenario, current versions of the module do not work at all with Histoire and the HstNuxt plugin. For the apollo scenario, common mocking strategies depend on apollo actually trying to fetch - so the fetch can be intercepted. This doesn't work either.

Instead of taking the big bang approach, and just letting everything through - this approach is an attempt to give the developer a choice of what to include, exclude or mock.

This introduces options for HstNuxt, so the developer can pick and choose.

This fixes #703 (and provides an example for Histoire + Nuxt3 + @nuxtjs/i18n - as well as tests for same).

There is another PR that solves some of the same problems (#710). However, for design system uses - I find that the addition of mocking is useful.


What is the purpose of this pull request?

  • [X] Bug fix
  • [X] New Feature
  • [ ] Documentation update
  • [ ] Other

Before submitting the PR, please make sure you do the following

  • [ ] If it's a new feature, provide a convincing reason to add it. Ideally, you should open a suggestion issue first and have it approved before working on it.
  • [X] Read the Contributing Guidelines.
  • [X] Read the Pull Request Guidelines and follow the Commit Convention.
  • [X] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • [X] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • [X] Ideally, include relevant tests that fail without this PR but pass with it.

filiphazardous avatar Aug 02 '24 09:08 filiphazardous