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

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

Open
wants to merge 1 commit into
base: master
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();
});
});