]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
test: use jest-mock-warn
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 23 Jun 2020 08:03:21 +0000 (10:03 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 23 Jun 2020 08:03:21 +0000 (10:03 +0200)
__tests__/ssr/app/main.ts
__tests__/ssr/ssrPlugin.spec.ts
package.json
src/ssrPlugin.ts
tsconfig.json
yarn.lock

index 88fcd2aa1a8ece19ff87f9a691a94b56da25bd89..94f5df80605f2e64a3dad917d06e8097f9c6e5cb 100644 (file)
@@ -8,6 +8,7 @@ import App from './App'
 export function createApp() {
   // create the app instance, injecting both the router and the store
   const app = new Vue({
+    // @ts-ignore
     render: h => h(App),
   })
 
index f67b8a8a13ee321f7589a25f808017955b38cae0..bc3a8cd4f745f9033f81f6c6751ea532e64c1b68 100644 (file)
@@ -1,12 +1,15 @@
 import Vue from 'vue'
 import { PiniaSsr } from '../../src'
+import { mockWarn } from 'jest-mock-warn'
 
-it('should warn when installed in the browser', () => {
-  const mixinSpy = jest.spyOn(Vue, 'mixin')
-  const warnSpy = jest.spyOn(console, 'warn')
-  Vue.use(PiniaSsr)
-  expect(warnSpy).toHaveBeenCalledWith(
-    expect.stringMatching(/seems to be used in the browser bundle/i)
-  )
-  expect(mixinSpy).not.toHaveBeenCalled()
+describe('SSR', () => {
+  mockWarn()
+
+  it('should warn when installed in the browser', () => {
+    const mixinSpy = jest.spyOn(Vue, 'mixin')
+    Vue.use(PiniaSsr)
+    expect(/seems to be used in the client bundle/i).toHaveBeenWarned()
+    expect(mixinSpy).not.toHaveBeenCalled()
+    mixinSpy.mockRestore()
+  })
 })
index 4117c22a3e3e5d83a116c13e3475b2463e5d6b8a..cbf3c012934ef25de6b42c153028c20ce7394c02 100644 (file)
@@ -47,6 +47,7 @@
     "eslint-config-prettier": "^6.10.0",
     "eslint-plugin-prettier": "^3.1.1",
     "jest": "^25.1.0",
+    "jest-mock-warn": "^1.1.0",
     "pascalcase": "^1.0.0",
     "prettier": "^1.18.2",
     "rimraf": "^3.0.1",
index 6cda44caba7af9ce205134ab45becdebc0346dc4..ea01adf1a140abb3b2d1dd43d71f57951c18b192 100644 (file)
@@ -7,7 +7,7 @@ export const PiniaSsr = (vue: VueConstructor) => {
 
   if (!isServer) {
     console.warn(
-      '`PiniaSsrPlugin` seems to be used in the browser bundle. You should only call it on the server entry: https://github.com/posva/pinia#raw-vue-ssr'
+      '`PiniaSsrPlugin` seems to be used in the client bundle. You should only call it on the server entry: https://github.com/posva/pinia#raw-vue-ssr'
     )
     return
   }
index 3d5d2bbe98159a46b64da599efe1b3e9351f3f41..471be985666f39be9ed1dbfbb485853fd61d81d3 100644 (file)
@@ -13,5 +13,5 @@
     "rootDir": ".",
     "baseUrl": "."
   },
-  "include": ["src/**/*.ts", "nuxt/*.js", "__tests__/**/**.ts"]
+  "include": ["src/**/*.ts", "nuxt/*.js", "__tests__/**/*.ts"]
 }
index c285b41e70029070e7e7ce4c7beca80b894ac14e..05bb7502ed0603eb71e7afaff92fa296237e842c 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -3168,6 +3168,11 @@ jest-message-util@^25.5.0:
     slash "^3.0.0"
     stack-utils "^1.0.1"
 
+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@^25.5.0:
   version "25.5.0"
   resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-25.5.0.tgz#a91a54dabd14e37ecd61665d6b6e06360a55387a"