Tests are failing when there is an action called in the mounted hook #2833
Unanswered
roshmani
asked this question in
Help and Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All,
// Component
`export default {
name: "Mycomponent",
components: {
ComponentA,
ComponentB,
},
data() {
return {
order: {},
allorders: [],
.....
};
},
computed: {
...mapStores(useAStore, useBStore, useCStore),
orderID() {
return getID();
},
shouldOrderBeInitialized() {
return (
this.AStore.someValue
);
},
// unit test
`const piniaInstance = createTestingPinia({
initialState: {
orders: {
ordersContainer: mockOrders,
},
},
stubActions: true,
createSpy: vi.fn(),
});
const getWrapper = async () => {
return mount(Mycomponent, {
global: {
plugins: [piniaInstance, router],
provide: {
showConfirm: vi.fn(),
},
mocks: {
$getUniqueId,
$debounce,
},
stubs: {
ComponentA: true,
},
},
});
};
describe("Mycomponent", () => {
let wrapper;
let store = useAStore();
beforeEach(() => {
wrapper = getWrapper();
store.loadOrderDataByID = vi
.fn()
.mockImplementationOnce(() => Promise.resolve(mockOrders));
});
test("builds", async () => {
expect(wrapper).toBeTruthy();
});
test("matches snapshot", () => {
expect(wrapper.element).toMatchSnapshot();
});
.....
});`
It fails giving an error "TypeError: this.AStore.loadOrderDataByID is not a function
at Proxy.mounted (...e.vue:90:36) "
and the snapshot is undefined, how can it be fixed ?
Thanks in advance,
RM
Beta Was this translation helpful? Give feedback.
All reactions