return array
}
-it('should patch previously empty children', () => {
+test('should patch previously empty children', () => {
const root = nodeOps.createElement('div')
render(h('div', []), root)
expect(inner(root)).toBe('<div>hello</div>')
})
-it('should patch previously null children', () => {
+test('should patch previously null children', () => {
const root = nodeOps.createElement('div')
render(h('div'), root)
expect(inner(root)).toBe('<div>hello</div>')
})
+test('array children -> text children', () => {
+ const root = nodeOps.createElement('div')
+ render(h('div', [h('div')]), root)
+ expect(inner(root)).toBe('<div><div></div></div>')
+
+ render(h('div', 'hello'), root)
+ expect(inner(root)).toBe('<div>hello</div>')
+})
+
describe('renderer: keyed children', () => {
let root: TestElement
let elm: TestElement
root
)
expect(serializeInner(root)).toBe(`<div>foo</div>barbaz`)
+
+ render(
+ createVNode(
+ Fragment,
+ null,
+ [
+ createTextVNode('baz'),
+ createVNode('div', null, 'foo', PatchFlags.TEXT)
+ ],
+ PatchFlags.UNKEYED_FRAGMENT
+ ),
+ root
+ )
+ expect(serializeInner(root)).toBe(`baz<div>foo</div>`)
})
it('patch fragment children (compiler generated, keyed)', () => {
const classify = (str: string): string =>
str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '')
+/* istanbul ignore next */
export function formatComponentName(
instance: ComponentInternalInstance | null,
Component: Component,
)
} else {
const warnArgs = [`[Vue warn]: ${msg}`, ...args]
+ /* istanbul ignore if */
if (
trace.length &&
// avoid spamming console during tests
return normalizedStack
}
+/* istanbul ignore next */
function formatTrace(trace: ComponentTraceStack): any[] {
const logs: any[] = []
trace.forEach((entry, i) => {
: [open + close]
}
+/* istanbul ignore next */
function formatProps(props: Data): any[] {
const res: any[] = []
const keys = Object.keys(props)
function formatProp(key: string, value: unknown): any[]
function formatProp(key: string, value: unknown, raw: true): any
+/* istanbul ignore next */
function formatProp(key: string, value: unknown, raw?: boolean): any {
if (isString(value)) {
value = JSON.stringify(value)
--- /dev/null
+import { render, h, nodeOps } from '@vue/runtime-test'
+import { useCssModule } from '../../src/helpers/useCssModule'
+import { mockWarn } from '@vue/shared'
+
+describe('useCssModule', () => {
+ mockWarn()
+
+ function mountWithModule(modules: any, name?: string) {
+ let res
+ render(
+ h({
+ render() {},
+ __cssModules: modules,
+ setup() {
+ res = useCssModule(name)
+ }
+ }),
+ nodeOps.createElement('div')
+ )
+ return res
+ }
+
+ test('basic usage', () => {
+ const modules = {
+ $style: {
+ red: 'red'
+ }
+ }
+ expect(mountWithModule(modules)).toMatchObject(modules.$style)
+ })
+
+ test('basic usage', () => {
+ const modules = {
+ foo: {
+ red: 'red'
+ }
+ }
+ expect(mountWithModule(modules, 'foo')).toMatchObject(modules.foo)
+ })
+
+ test('warn out of setup usage', () => {
+ useCssModule()
+ expect('must be called inside setup').toHaveBeenWarned()
+ })
+
+ test('warn missing injection', () => {
+ mountWithModule(undefined)
+ expect('instance does not have CSS modules').toHaveBeenWarned()
+ })
+
+ test('warn missing injection', () => {
+ mountWithModule({ $style: { red: 'red' } }, 'foo')
+ expect('instance does not have CSS module named "foo"').toHaveBeenWarned()
+ })
+})
import { EMPTY_OBJ } from '@vue/shared'
export function useCssModule(name = '$style'): Record<string, string> {
+ /* istanbul ignore else */
if (!__GLOBAL__) {
const instance = getCurrentInstance()!
if (!instance) {
- __DEV__ && warn(`useCSSModule must be called inside setup()`)
+ __DEV__ && warn(`useCssModule must be called inside setup()`)
return EMPTY_OBJ
}
const modules = instance.type.__cssModules
return mod as Record<string, string>
} else {
if (__DEV__) {
- warn(`useCSSModule() is not supported in the global build.`)
+ warn(`useCssModule() is not supported in the global build.`)
}
return EMPTY_OBJ
}
scoped = false
) {
const instance = getCurrentInstance()
+ /* istanbul ignore next */
if (!instance) {
__DEV__ &&
warn(`useCssVars is called without current active component instance.`)