Skip to content

Commit

Permalink
test: use jest-mock-warn
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jun 23, 2020
1 parent 113aa0f commit bc2f049
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
1 change: 1 addition & 0 deletions __tests__/ssr/app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})

Expand Down
19 changes: 11 additions & 8 deletions __tests__/ssr/ssrPlugin.spec.ts
Original file line number Diff line number Diff line change
@@ -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()
})
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/ssrPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"rootDir": ".",
"baseUrl": "."
},
"include": ["src/**/*.ts", "nuxt/*.js", "__tests__/**/**.ts"]
"include": ["src/**/*.ts", "nuxt/*.js", "__tests__/**/*.ts"]
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit bc2f049

Please sign in to comment.