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

[Bug] Vitest is not supported #12

Open
IamTugy opened this issue Jan 13, 2025 · 1 comment
Open

[Bug] Vitest is not supported #12

IamTugy opened this issue Jan 13, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@IamTugy
Copy link

IamTugy commented Jan 13, 2025

Describe the bug

When using vitest to run the tests it doesnt load the query parameters

Steps to reproduce the behavior

create a story and show the query param
create a play function that looks for the query param
the test will fail

Expected behavior

The query param should be loaded

@IamTugy IamTugy added the bug Something isn't working label Jan 13, 2025
@IamTugy
Copy link
Author

IamTugy commented Jan 15, 2025

ive solved it by using the logic inside the beforeEach:

  beforeEach: async ({ parameters, mount, canvasElement }) => {
    const { location } = document;
    if (parameters.query) {
      const currentQuery = new URLSearchParams(location.search);
      const additionalQuery =
        typeof parameters.query === "string"
          ? new URLSearchParams(parameters.query)
          : parameters.query;

      const newLocation = new URL(document.location.href);
      newLocation.search = new URLSearchParams({
        ...currentQuery,
        ...additionalQuery,
      }).toString();

      history.replaceState({}, document.title, newLocation.toString());
    }
    return () => {
      // reset query search params:
      history.replaceState({}, document.title, location.toString());
    };
  },
} satisfies Preview;

@IamTugy IamTugy changed the title [Bug] Vitetest is not supported [Bug] Vitest is not supported Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant