Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
A tutorial and starter template for writing testable Nuxt.js apps with TypeScript, Jest, and class-based Vue components.
Nuxt Testable is a GitHub repository and tutorial that demonstrates how to write testable Nuxt.js applications using TypeScript, class-based Vue components, and Jest as the test runner. It walks through building a modular todo application step by step, with tests written before implementation, so you can see a realistic TDD workflow for a Nuxt + Vuex project.
Nuxt Testable is a community-written guide and starter project (author: nesterow) based on the Nuxt Community typescript-template. Its core function is to show concrete patterns for unit-testing Vuex stores and Vue components in a Nuxt app. The project takes a fresh Nuxt TypeScript skeleton as input and produces a modular application structure with Jest configuration, dependency injection, and mocked API calls as output.
nuxt-property-decorator and vuex-module-decorators to write components and store modules as TypeScript classes, enabling inheritance and OOP patterns.package.json Jest settings for vue-jest, ts-jest, and babel-jest transforms, plus testRegex for spec files and testURL: http://localhost/.window/document references.components and middleware directories with a modules folder, where each module groups its own components, store, types, tests, and index.vue.provide-consume-decorator — Provides @provideVuex / @consume decorators to inject an axios instance (or any dependency) into Vuex modules and components, making them configurable and abstracted from concrete implementations.stateFactory: true in vuex-module-decorators to avoid module caching issues that cause shared state across test instances and SSR clients.axios-mock-adapter to create a fake REST API (/todos endpoints) so actions can be tested without a real server.__factory.ts helper mounts Vue components with a configured Vuex store and injected dependencies, so the same setup can be reused across component specs.getModule() from vuex-module-decorators and a mocked axios adapter.@vue/test-utils, using factory functions and provided/injected store instances.vue init nuxt-community/typescript-template, then follow the instructions to add Jest, Babel plugins, and the required dependencies.@Module and @Mutation/@Action decorators, and iterate until tests pass.axios-mock-adapter to stub GET/POST/PUT/DELETE /todos routes, so actions can be tested against realistic responses.AddTodo.vue and TodoList.vue with a factory that injects a mocked Vuex store, then assert that component state and store state update correctly after calling methods.The tutorial is organized as a sequence of steps: first, generate the Nuxt TypeScript skeleton and install dependencies (vuex-module-decorators, provide-consume-decorator, axios-mock-adapter, and Jest-related packages). Next, add Jest and Babel configuration to package.json and tsconfig.json. Then define a TypeScript interface for the store, write a failing spec, and implement the Vuex module using class decorators. Component testing follows the same pattern: write a spec, run it, and make it pass by adding component logic. Finally, connect the module to the Nuxt app via ~/store/index.ts and mount the parent component on a page.
Nuxt Testable is a public GitHub repository (17 stars) that contains a tutorial and example code for building Nuxt applications with testable TypeScript code. It focuses on unit-testing Vuex stores and Vue components using Jest, class-based components, and dependency injection.
The project uses Jest as the test runner with vue-jest, ts-jest, and babel-jest for transformation. It also uses @vue/test-utils for mounting components, vuex-module-decorators for store classes, and axios-mock-adapter for mocking HTTP requests.
Yes. Both Vue components and Vuex modules are written as TypeScript classes using nuxt-property-decorator and vuex-module-decorators. This allows the author to apply inheritance, decorators, and OOP patterns instead of the options-object style.
The repository is publicly available on GitHub without any stated license restrictions, and the tutorial code can be freely used as a reference or starter. The setup commands use standard npm install steps that are common to open-source projects.
