Skip to content

Commit 5c74243

Browse files
committed
test: move mockWarn into setup files
1 parent d452723 commit 5c74243

35 files changed

+103
-199
lines changed

jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
preset: 'ts-jest',
3+
setupFilesAfterEnv: ['./scripts/setupJestEnv.ts'],
34
globals: {
45
__DEV__: true,
56
__TEST__: true,

packages/compiler-sfc/__tests__/compileStyle.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ import {
77
compileStyleAsync,
88
SFCStyleCompileOptions
99
} from '../src/compileStyle'
10-
import { mockWarn } from '@vue/shared'
1110
import path from 'path'
1211

1312
describe('SFC scoped CSS', () => {
14-
mockWarn()
15-
1613
function compileScoped(
1714
source: string,
1815
options?: Partial<SFCStyleCompileOptions>

packages/global.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ declare var __VERSION__: string
1313
declare var __FEATURE_OPTIONS_API__: boolean
1414
declare var __FEATURE_PROD_DEVTOOLS__: boolean
1515
declare var __FEATURE_SUSPENSE__: boolean
16+
17+
// for tests
18+
declare namespace jest {
19+
interface Matchers<R, T> {
20+
toHaveBeenWarned(): R
21+
toHaveBeenWarnedLast(): R
22+
toHaveBeenWarnedTimes(n: number): R
23+
}
24+
}

packages/reactivity/__tests__/collections/Map.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { reactive, effect, toRaw, isReactive } from '../../src'
2-
import { mockWarn } from '@vue/shared'
32

43
describe('reactivity/collections', () => {
54
describe('Map', () => {
6-
mockWarn()
7-
85
test('instanceof', () => {
96
const original = new Map()
107
const observed = reactive(original)

packages/reactivity/__tests__/collections/Set.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { reactive, effect, isReactive, toRaw } from '../../src'
2-
import { mockWarn } from '@vue/shared'
32

43
describe('reactivity/collections', () => {
54
describe('Set', () => {
6-
mockWarn()
7-
85
it('instanceof', () => {
96
const original = new Set()
107
const observed = reactive(original)

packages/reactivity/__tests__/computed.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ import {
77
WritableComputedRef,
88
isReadonly
99
} from '../src'
10-
import { mockWarn } from '@vue/shared'
1110

1211
describe('reactivity/computed', () => {
13-
mockWarn()
14-
1512
it('should return updated value', () => {
1613
const value = reactive<{ foo?: number }>({})
1714
const cValue = computed(() => value.foo)

packages/reactivity/__tests__/reactive.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { ref, isRef } from '../src/ref'
22
import { reactive, isReactive, toRaw, markRaw } from '../src/reactive'
3-
import { mockWarn } from '@vue/shared'
43
import { computed } from '../src/computed'
54

65
describe('reactivity/reactive', () => {
7-
mockWarn()
8-
96
test('Object', () => {
107
const original = { foo: 1 }
118
const observed = reactive(original)

packages/reactivity/__tests__/readonly.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@ import {
1010
shallowReadonly,
1111
isProxy
1212
} from '../src'
13-
import { mockWarn } from '@vue/shared'
1413

1514
/**
1615
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html
1716
*/
1817
type Writable<T> = { -readonly [P in keyof T]: T[P] }
1918

2019
describe('reactivity/readonly', () => {
21-
mockWarn()
22-
2320
describe('Object', () => {
2421
it('should make nested values readonly', () => {
2522
const original = { foo: 1, bar: { baz: 2 } }

packages/runtime-core/__tests__/apiCreateApp.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ import {
1313
getCurrentInstance,
1414
defineComponent
1515
} from '@vue/runtime-test'
16-
import { mockWarn } from '@vue/shared'
1716

1817
describe('api: createApp', () => {
19-
mockWarn()
20-
2118
test('mount', () => {
2219
const Comp = defineComponent({
2320
props: {

packages/runtime-core/__tests__/apiInject.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ import {
1010
reactive
1111
} from '../src/index'
1212
import { render, nodeOps, serialize } from '@vue/runtime-test'
13-
import { mockWarn } from '@vue/shared'
1413

1514
// reference: https://vue-composition-api-rfc.netlify.com/api.html#provide-inject
16-
1715
describe('api: provide/inject', () => {
18-
mockWarn()
19-
2016
it('string keys', () => {
2117
const Provider = {
2218
setup() {

packages/runtime-core/__tests__/apiOptions.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
ref,
1111
defineComponent
1212
} from '@vue/runtime-test'
13-
import { mockWarn } from '@vue/shared'
1413

1514
describe('api: options', () => {
1615
test('data', async () => {
@@ -705,8 +704,6 @@ describe('api: options', () => {
705704
})
706705

707706
describe('warnings', () => {
708-
mockWarn()
709-
710707
test('Expected a function as watch handler', () => {
711708
const Comp = {
712709
watch: {

packages/runtime-core/__tests__/apiWatch.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ import {
1414
TrackOpTypes,
1515
TriggerOpTypes
1616
} from '@vue/reactivity'
17-
import { mockWarn } from '@vue/shared'
1817

1918
// reference: https://vue-composition-api-rfc.netlify.com/api.html#watch
2019

2120
describe('api: watch', () => {
22-
mockWarn()
23-
2421
it('effect', async () => {
2522
const state = reactive({ count: 0 })
2623
let dummy

packages/runtime-core/__tests__/componentEmits.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
// Note: emits and listener fallthrough is tested in
22
// ./rendererAttrsFallthrough.spec.ts.
33

4-
import { mockWarn } from '@vue/shared'
54
import { render, defineComponent, h, nodeOps } from '@vue/runtime-test'
65
import { isEmitListener } from '../src/componentEmits'
76

87
describe('component: emit', () => {
9-
mockWarn()
10-
118
test('trigger handlers', () => {
129
const Foo = defineComponent({
1310
render() {},

packages/runtime-core/__tests__/componentProps.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ import {
1010
serializeInner
1111
} from '@vue/runtime-test'
1212
import { render as domRender, nextTick } from 'vue'
13-
import { mockWarn } from '@vue/shared'
1413

1514
describe('component props', () => {
16-
mockWarn()
17-
1815
test('stateful', () => {
1916
let props: any
2017
let attrs: any

packages/runtime-core/__tests__/componentProxy.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ import {
66
createApp,
77
shallowReadonly
88
} from '@vue/runtime-test'
9-
import { mockWarn } from '@vue/shared'
109
import { ComponentInternalInstance } from '../src/component'
1110

1211
describe('component: proxy', () => {
13-
mockWarn()
14-
1512
test('data', () => {
1613
let instance: ComponentInternalInstance
1714
let instanceProxy: any

packages/runtime-core/__tests__/errorHandling.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ import {
1111
watchEffect
1212
} from '@vue/runtime-test'
1313
import { setErrorRecovery } from '../src/errorHandling'
14-
import { mockWarn } from '@vue/shared'
1514

1615
describe('error handling', () => {
17-
mockWarn()
18-
1916
beforeEach(() => {
2017
setErrorRecovery(true)
2118
})

packages/runtime-core/__tests__/helpers/renderSlot.spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { renderSlot } from '../../src/helpers/renderSlot'
22
import { h } from '../../src/h'
3-
import { mockWarn } from '@vue/shared'
43

54
describe('renderSlot', () => {
6-
mockWarn()
75
it('should render slot', () => {
86
let child
97
const vnode = renderSlot(

packages/runtime-core/__tests__/helpers/resolveAssets.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ import {
1212
Comment,
1313
VNode
1414
} from '@vue/runtime-test'
15-
import { mockWarn } from '@vue/shared'
1615

1716
describe('resolveAssets', () => {
18-
mockWarn()
19-
2017
test('should work', () => {
2118
const FooBar = () => null
2219
const BarBaz = { mounted: () => null }

packages/runtime-core/__tests__/helpers/toHandlers.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { toHandlers } from '../../src/helpers/toHandlers'
2-
import { mockWarn } from '@vue/shared'
32

43
describe('toHandlers', () => {
5-
mockWarn()
6-
74
it('should not accept non-objects', () => {
85
toHandlers(null as any)
96
toHandlers(undefined as any)

packages/runtime-core/__tests__/hydration.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
defineComponent
1313
} from '@vue/runtime-dom'
1414
import { renderToString, SSRContext } from '@vue/server-renderer'
15-
import { mockWarn } from '@vue/shared'
1615

1716
function mountWithHydration(html: string, render: () => any) {
1817
const container = document.createElement('div')
@@ -34,8 +33,6 @@ const triggerEvent = (type: string, el: Element) => {
3433
}
3534

3635
describe('SSR hydration', () => {
37-
mockWarn()
38-
3936
beforeEach(() => {
4037
document.body.innerHTML = ''
4138
})

packages/runtime-core/__tests__/rendererAttrsFallthrough.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ import {
1313
createCommentVNode,
1414
Fragment
1515
} from '@vue/runtime-dom'
16-
import { mockWarn } from '@vue/shared'
1716

1817
describe('attribute fallthrough', () => {
19-
mockWarn()
20-
2118
it('should allow attrs to fallthrough', async () => {
2219
const click = jest.fn()
2320
const childUpdated = jest.fn()

packages/runtime-core/__tests__/rendererChildren.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import {
88
serialize,
99
serializeInner
1010
} from '@vue/runtime-test'
11-
import { mockWarn } from '@vue/shared'
12-
13-
mockWarn()
14-
1511
function toSpan(content: any) {
1612
if (typeof content === 'string') {
1713
return h('span', content.toString())

packages/runtime-core/__tests__/vnode.spec.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ import {
1111
transformVNodeArgs
1212
} from '../src/vnode'
1313
import { Data } from '../src/component'
14-
import { ShapeFlags, PatchFlags, mockWarn } from '@vue/shared'
14+
import { ShapeFlags, PatchFlags } from '@vue/shared'
1515
import { h, reactive, isReactive } from '../src'
1616
import { createApp, nodeOps, serializeInner } from '@vue/runtime-test'
1717
import { setCurrentRenderingInstance } from '../src/componentRenderUtils'
1818

1919
describe('vnode', () => {
20-
mockWarn()
21-
2220
test('create with just tag', () => {
2321
const vnode = createVNode('p')
2422
expect(vnode.type).toBe('p')

packages/runtime-dom/__tests__/helpers/useCssModule.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { render, h, nodeOps } from '@vue/runtime-test'
22
import { useCssModule } from '../../src/helpers/useCssModule'
3-
import { mockWarn } from '@vue/shared'
43

54
describe('useCssModule', () => {
6-
mockWarn()
7-
85
function mountWithModule(modules: any, name?: string) {
96
let res
107
render(

packages/runtime-dom/__tests__/patchProps.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { patchProp } from '../src/patchProp'
22
import { render, h } from '../src'
3-
import { mockWarn } from '@vue/shared'
43

54
describe('runtime-dom: props patching', () => {
6-
mockWarn()
7-
85
test('basic', () => {
96
const el = document.createElement('div')
107
patchProp(el, 'id', null, 'foo')

packages/runtime-test/__tests__/testRuntime.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ import {
1414
serialize,
1515
triggerEvent
1616
} from '../src'
17-
import { mockWarn } from '@vue/shared'
1817

1918
describe('test renderer', () => {
20-
mockWarn()
21-
2219
it('should work', () => {
2320
const root = nodeOps.createElement('div')
2421
render(

packages/server-renderer/__tests__/renderToStream.spec.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,11 @@ import {
1010
createTextVNode,
1111
createStaticVNode
1212
} from 'vue'
13-
import { escapeHtml, mockWarn } from '@vue/shared'
13+
import { escapeHtml } from '@vue/shared'
1414
import { renderToStream as _renderToStream } from '../src/renderToStream'
1515
import { Readable } from 'stream'
1616
import { ssrRenderSlot } from '../src/helpers/ssrRenderSlot'
1717
import { ssrRenderComponent } from '../src/helpers/ssrRenderComponent'
18-
19-
mockWarn()
20-
2118
const promisifyStream = (stream: Readable) => {
2219
return new Promise((resolve, reject) => {
2320
let result = ''

packages/server-renderer/__tests__/renderToString.spec.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ import {
1010
createTextVNode,
1111
createStaticVNode
1212
} from 'vue'
13-
import { escapeHtml, mockWarn } from '@vue/shared'
13+
import { escapeHtml } from '@vue/shared'
1414
import { renderToString } from '../src/renderToString'
1515
import { ssrRenderSlot, SSRSlot } from '../src/helpers/ssrRenderSlot'
1616
import { ssrRenderComponent } from '../src/helpers/ssrRenderComponent'
17-
18-
mockWarn()
19-
2017
describe('ssr: renderToString', () => {
2118
test('should apply app context', async () => {
2219
const app = createApp({

packages/server-renderer/__tests__/ssrSuspense.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { createApp, h, Suspense } from 'vue'
22
import { renderToString } from '../src/renderToString'
3-
import { mockWarn } from '@vue/shared'
43

54
describe('SSR Suspense', () => {
6-
mockWarn()
7-
85
const ResolvingAsync = {
96
async setup() {
107
return () => h('div', 'async')

packages/shared/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export * from './shapeFlags'
66
export * from './slotFlags'
77
export * from './globalsWhitelist'
88
export * from './codeframe'
9-
export * from './mockWarn'
109
export * from './normalizeProp'
1110
export * from './domTagConfig'
1211
export * from './domAttrConfig'

0 commit comments

Comments
 (0)