Skip to content
This repository has been archived by the owner on Mar 4, 2025. It is now read-only.

feat: Automatically import component and store in jest. #802

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ module.exports = {
'<rootDir>/components/**/*.vue',
'<rootDir>/pages/**/*.vue'
],
testEnvironment: 'jsdom'
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['./jest.setup.js'],
}
2 changes: 2 additions & 0 deletions packages/cna-template/template/frameworks/jest/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Enable when you want to import components automatically.
import "./.nuxt/components/plugin.js";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this should be enabled by default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed when components: true is not provided, this file does not exists... Maybe using import().catch(()=>{})? But i think other than this, by default we have components: true in default CNA nuxt config

Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { mount } from '@vue/test-utils'
import NuxtLogo from '@/components/NuxtLogo.vue'
import { mount } from "@vue/test-utils";
import NuxtLogo from "@/components/NuxtLogo.vue";
import Vuex from "vuex";
// Enable when you want to import Vuex Srore automatically.
import { createStore } from "../.nuxt/store.js";

describe('NuxtLogo', () => {
test('is a Vue instance', () => {
const wrapper = mount(NuxtLogo)
expect(wrapper.vm).toBeTruthy()
})
})
const localVue = createLocalVue();
localVue.use(Vuex);

describe("NuxtLogo", () => {
test("is a Vue instance", () => {
const store = createStore();
const wrapper = mount(NuxtLogo, {
store,
localVue,
});
expect(wrapper.vm).toBeTruthy();
});
});