From cc7b79e6f17e746e88c30a5b83b937eae1479412 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Fri, 25 Jun 2021 15:46:23 +0200 Subject: [PATCH] chore: fix typing issue --- src/testing.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/testing.ts b/src/testing.ts index df7677d9..274642ac 100644 --- a/src/testing.ts +++ b/src/testing.ts @@ -1,6 +1,5 @@ import { createPinia } from './createPinia' -import { PiniaStorePlugin, setActivePinia } from './rootStore' -import { GettersTree, StateTree, Store } from './types' +import { Pinia, PiniaStorePlugin, setActivePinia } from './rootStore' export interface TestingOptions { /** @@ -18,6 +17,13 @@ export interface TestingOptions { createSpy?: (fn?: (...args: any[]) => any) => (...args: any[]) => any } +export interface TestingPinia extends Pinia { + /** + * Clears the cache of spies used for actions. + */ + resetSpyCache(): void +} + /** * Creates a pinia instance designed for unit tests that **requires mocking** * the stores. By default, **all actions are mocked** and therefore not @@ -33,7 +39,7 @@ export function createTestingPinia({ plugins = [], bypassActions = true, createSpy, -}: TestingOptions = {}) { +}: TestingOptions = {}): TestingPinia { const pinia = createPinia() plugins.forEach((plugin) => pinia.use(plugin)) @@ -67,5 +73,12 @@ export function createTestingPinia({ setActivePinia(pinia) - return pinia + return Object.assign( + { + resetSpyCache() { + spiedActions.clear() + }, + }, + pinia + ) } -- 2.47.2