From bc2f04982bf51a24d400aabdee75fe66ff04c753 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 23 Jun 2020 10:03:21 +0200 Subject: [PATCH] test: use jest-mock-warn --- __tests__/ssr/app/main.ts | 1 + __tests__/ssr/ssrPlugin.spec.ts | 19 +++++++++++-------- package.json | 1 + src/ssrPlugin.ts | 2 +- tsconfig.json | 2 +- yarn.lock | 5 +++++ 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/__tests__/ssr/app/main.ts b/__tests__/ssr/app/main.ts index 88fcd2aa1a..94f5df8060 100644 --- a/__tests__/ssr/app/main.ts +++ b/__tests__/ssr/app/main.ts @@ -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), }) diff --git a/__tests__/ssr/ssrPlugin.spec.ts b/__tests__/ssr/ssrPlugin.spec.ts index f67b8a8a13..bc3a8cd4f7 100644 --- a/__tests__/ssr/ssrPlugin.spec.ts +++ b/__tests__/ssr/ssrPlugin.spec.ts @@ -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() + }) }) diff --git a/package.json b/package.json index 4117c22a3e..cbf3c01293 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/ssrPlugin.ts b/src/ssrPlugin.ts index 6cda44caba..ea01adf1a1 100644 --- a/src/ssrPlugin.ts +++ b/src/ssrPlugin.ts @@ -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 } diff --git a/tsconfig.json b/tsconfig.json index 3d5d2bbe98..471be98566 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,5 +13,5 @@ "rootDir": ".", "baseUrl": "." }, - "include": ["src/**/*.ts", "nuxt/*.js", "__tests__/**/**.ts"] + "include": ["src/**/*.ts", "nuxt/*.js", "__tests__/**/*.ts"] } diff --git a/yarn.lock b/yarn.lock index c285b41e70..05bb7502ed 100644 --- 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"