{"id":15534757,"url":"https://github.com/ssekpius/how-to-test-nuxt-stores","last_synced_at":"2026-01-07T17:06:46.396Z","repository":{"id":78535279,"uuid":"584823102","full_name":"SSEKPIUS/how-to-test-nuxt-stores","owner":"SSEKPIUS","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-08T15:28:42.000Z","size":1029,"stargazers_count":0,"open_issues_count":8,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T22:45:46.558Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SSEKPIUS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-03T15:54:07.000Z","updated_at":"2023-01-31T23:02:59.000Z","dependencies_parsed_at":"2023-03-10T22:00:56.101Z","dependency_job_id":null,"html_url":"https://github.com/SSEKPIUS/how-to-test-nuxt-stores","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SSEKPIUS/how-to-test-nuxt-stores","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SSEKPIUS%2Fhow-to-test-nuxt-stores","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SSEKPIUS%2Fhow-to-test-nuxt-stores/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SSEKPIUS%2Fhow-to-test-nuxt-stores/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SSEKPIUS%2Fhow-to-test-nuxt-stores/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SSEKPIUS","download_url":"https://codeload.github.com/SSEKPIUS/how-to-test-nuxt-stores/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SSEKPIUS%2Fhow-to-test-nuxt-stores/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28236384,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2026-01-07T02:00:05.975Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T11:43:23.269Z","updated_at":"2026-01-07T17:06:46.321Z","avatar_url":"https://github.com/SSEKPIUS.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to Test Nuxt Stores\n\nI would argue that testing your stores is the most important part of your front end app that needs testing. Unfortunately, it's not well-documented how to do this with a Nuxt app.\n\n## The Problem\nNuxt is building up Vuex modules for you under the hood, but you can't just import the stores like you would import a file. The magic happens during nuxt's build step, and that's what we need access to.\n\n## The Solution\nThe majority of the magic is happening in `jest.setup.js`. There are three primary steps here:\n1. Overrides: we override the default config for building nuxt, disabling everything but the `store` feature. We also override the mode (no need for SSR when testing stores), and ignore unneccessary folders.\n2. We kick off a nuxt build, and we wait...\n3. When it completes, we set an env var for ourselves for later: the `buildDir`. We'll need that to create the store in our tests.\n\nThe rest of the magic comes into play in the setup of `movies.test.js`. This whole part of the setup is the other critical piece in this puzzle:\n```js\nconst localVue = createLocalVue();\nlocalVue.use(Vuex);\nlet NuxtStore;\nlet store;\n\nbeforeAll(async () =\u003e {\n  // note the store will mutate across tests\n  const storePath = `${process.env.buildDir}/store.js`;\n  NuxtStore = await import(storePath);\n});\n\nbeforeEach(async () =\u003e {\n  store = await NuxtStore.createStore();\n});\n```\n\n## Notes\n\n### Mutations and Actions\nYou an _see_ the mutations and actions on the store as they're stored with the private variable convetion of `_mutations` and `_actions`, respectively. However, the store also has `commit` and `dispatch` on it, so you can use it as you would in your actual application.\n\n_(Note for the future: Vue 3 will likely drop the need to commit an action to make a mutation, so this language may get out of date)_\n\n### `forceExit` in `jest.config.js`\nIn some CI environments, jest can hang, so this will force it to exit when tests are complete.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssekpius%2Fhow-to-test-nuxt-stores","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssekpius%2Fhow-to-test-nuxt-stores","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssekpius%2Fhow-to-test-nuxt-stores/lists"}