import { createPinia, defineStore } from '../src'
+import { mockWarn } from 'jest-mock-warn'
describe('Root State', () => {
+ mockWarn()
const useA = defineStore({
id: 'a',
state: () => ({ a: 'a' }),
state: () => ({ b: 'b' }),
})
+ it('warns if creating a store without a pinia', () => {
+ expect(() => useA()).toThrow()
+ expect('with no active Pinia').toHaveBeenWarned()
+ })
+
it('works with no stores', () => {
expect(createPinia().state.value).toEqual({})
})
'/node_modules/',
'src/index.ts',
'src/devtools.ts',
+ 'src/deprecated.ts',
],
testMatch: ['<rootDir>/__tests__/**/*.spec.ts'],
globals: {
"codecov": "^3.6.1",
"conventional-changelog-cli": "^2.1.0",
"jest": "^26.4.2",
+ "jest-mock-warn": "^1.1.0",
"lint-staged": "^10.2.11",
"pascalcase": "^1.0.0",
"prettier": "^2.1.2",
setupDevtoolsPlugin,
} from '@vue/devtools-api'
import { App } from 'vue'
-import { getRegisteredStores, registerStore } from './rootStore'
import { GenericStore } from './types'
function formatDisplay(display: string) {
}
}
+/**
+ * Registered stores used for devtools.
+ */
+export const stores = /*#__PURE__*/ new Set<GenericStore>()
+
+export function registerStore(store: GenericStore) {
+ stores.add(store)
+}
+
function toastMessage(
message: string,
type?: 'normal' | 'error' | 'warning' | undefined
api.on.getInspectorTree((payload) => {
if (payload.app === app && payload.inspectorId === piniaInspectorId) {
- const stores = Array.from(getRegisteredStores())
+ const stores = Array.from(stores)
payload.rootNodes = (payload.filter
? stores.filter((store) =>
api.on.getInspectorState((payload) => {
if (payload.app === app && payload.inspectorId === piniaInspectorId) {
- const stores = Array.from(getRegisteredStores())
+ const stores = Array.from(stores)
const store = stores.find((store) => store.$id === payload.nodeId)
if (store) {
StoreWithActions,
StoreWithState,
} from './types'
+
+// TODO: remove in beta
export { createStore } from './deprecated'
import { App, InjectionKey, Plugin, Ref, ref, warn } from 'vue'
import { IS_CLIENT } from './env'
-import {
- StateTree,
- GenericStore,
- StoreWithState,
- StateDescriptor,
-} from './types'
+import { StateTree, StoreWithState, StateDescriptor } from './types'
/**
* setActivePinia must be called to handle SSR at the top of functions like
export const piniaSymbol = (__DEV__
? Symbol('pinia')
- : Symbol()) as InjectionKey<Pinia>
+ : /* istanbul ignore next */
+ Symbol()) as InjectionKey<Pinia>
/**
* Creates a Pinia instance to be used by the application
},
use(plugin) {
+ /* istanbul ignore next */
if (__DEV__) {
console.warn(
`[🍍]: The plugin API has plans to change to bring better extensibility. "pinia.use()" signature will change in the next release. It is recommended to avoid using this API.`
* Properties that are added to every store by `pinia.use()`
*/
export interface PiniaCustomProperties {}
-
-/**
- * Registered stores used for devtools. TODO: move to devtools
- */
-export const stores = /*#__PURE__*/ new Set<GenericStore>()
-
-export function registerStore(store: GenericStore) {
- stores.add(store)
-}
-
-export const getRegisteredStores = () => stores
__DEV__ /*|| __FEATURE_PROD_DEVTOOLS__*/
) {
const app = getClientApp()
+ /* istanbul ignore else */
if (app) {
addDevtools(app, store)
} else if (!isDevWarned && !__TEST__) {
slash "^3.0.0"
stack-utils "^2.0.2"
+jest-mock-warn@^1.1.0:
+ version "1.1.0"
+ resolved "https://registry.yarnpkg.com/jest-mock-warn/-/jest-mock-warn-1.1.0.tgz#cb1c8beaa6c6236da2be0f170fd5e6f595adb67b"
+ integrity sha512-Q0EjGIUowgcuH7K1v6KgZ/WtqQaA9kc/TxayKaZKKeTGBn9nC4uKI65nt0O3l8opaPi2VSvG18WcLPEqzowxrQ==
+
jest-mock@^26.6.2:
version "26.6.2"
resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-26.6.2.tgz#d6cb712b041ed47fe0d9b6fc3474bc6543feb302"