Loading...
Loading...
Compare original and translation side by side
wrapper.vmbeforeEach()references/pinia-patterns.mdwrapper.vmbeforeEach()references/pinia-patterns.mdreferences/pinia-patterns.mdreferences/pinia-patterns.mdcreateTestingPiniacreateSpy: vi.fnconst wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
}),
],
},
});stubActions: truecreateTestingPiniacreateSpy: vi.fnconst wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
}),
],
},
});stubActions: truecreateTestingPinia({})createTestingPinia({ initialState: ... })createTestingPinia({ stubActions: ... })createSpysetActivePinia(createTestingPinia(...))createSpy: vi.fncreateTestingPinia({})createTestingPinia({ initialState: ... })createTestingPinia({ stubActions: ... })createSpysetActivePinia(createTestingPinia(...))createSpy: vi.fnstubActions: falseconst wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
stubActions: false,
}),
],
},
});stubActions: falseconst wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
stubActions: false,
}),
],
},
});initialStateinitialStateconst wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
initialState: {
counter: { n: 20 },
user: { name: "Leia Organa" },
},
}),
],
},
});const wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
initialState: {
counter: { n: 20 },
user: { name: "Leia Organa" },
},
}),
],
},
});createTestingPiniacreateTestingPiniaconst wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
plugins: [myPiniaPlugin],
}),
],
},
});const wrapper = mount(ComponentUnderTest, {
global: {
plugins: [
createTestingPinia({
createSpy: vi.fn,
plugins: [myPiniaPlugin],
}),
],
},
});const pinia = createTestingPinia({ createSpy: vi.fn });
const store = useCounterStore(pinia);
store.double = 999;
// @ts-expect-error test-only reset of overridden getter
store.double = undefined;const pinia = createTestingPinia({ createSpy: vi.fn });
const store = useCounterStore(pinia);
store.double = 999;
// @ts-expect-error test-only reset of overridden getter
store.double = undefined;createPinia()createTestingPinia()beforeEach(() => {
setActivePinia(createPinia());
});
it("increments", () => {
const counter = useCounterStore();
counter.increment();
expect(counter.n).toBe(1);
});createPinia()createTestingPinia()beforeEach(() => {
setActivePinia(createPinia());
});
it("increments", () => {
const counter = useCounterStore();
counter.increment();
expect(counter.n).toBe(1);
});findComponent(...).vm.$emit(...)nextTickwrapper.emitted(...)wrapper.vmfindComponent(...).vm.$emit(...)nextTickwrapper.emitted(...)wrapper.vmawait wrapper.find("button").trigger("click");
expect(wrapper.emitted("submit")?.[0]?.[0]).toBe("Mango Mission");await wrapper.find("input").setValue("Agent Violet");
await wrapper.find("form").trigger("submit");
expect(wrapper.emitted("save")?.[0]?.[0]).toBe("Agent Violet");await wrapper.find("button").trigger("click");
expect(wrapper.emitted("submit")?.[0]?.[0]).toBe("Mango Mission");await wrapper.find("input").setValue("Agent Violet");
await wrapper.find("form").trigger("submit");
expect(wrapper.emitted("save")?.[0]?.[0]).toBe("Agent Violet");createupdatereviewreferences/pinia-patterns.mdreferences/pinia-patterns.md