|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { |
| 3 | + createCommentVNode, |
| 4 | + createStaticVNode, |
| 5 | + createVNode, |
| 6 | + createTextVNode, |
| 7 | + defineAsyncComponent, |
| 8 | + Fragment, |
| 9 | + h, |
| 10 | + Text |
| 11 | +} from 'vue' |
| 12 | +import { |
| 13 | + getText, |
| 14 | + getType, |
| 15 | + isComment, |
| 16 | + isComponent, |
| 17 | + isElement, |
| 18 | + isFragment, |
| 19 | + isFunctionalComponent, |
| 20 | + isStatefulComponent, |
| 21 | + isStatic, |
| 22 | + isText |
| 23 | +} from '../base' |
| 24 | + |
| 25 | +describe('isComment', () => { |
| 26 | + it('isComment - 194a', () => { |
| 27 | + expect(isComment(undefined)).toBe(true) |
| 28 | + expect(isComment(null)).toBe(true) |
| 29 | + expect(isComment(false)).toBe(true) |
| 30 | + expect(isComment(true)).toBe(true) |
| 31 | + expect(isComment(createCommentVNode('Text'))).toBe(true) |
| 32 | + |
| 33 | + expect(isComment('')).toBe(false) |
| 34 | + expect(isComment(0)).toBe(false) |
| 35 | + expect(isComment(NaN)).toBe(false) |
| 36 | + expect(isComment(0n)).toBe(false) |
| 37 | + expect(isComment(createTextVNode('Text'))).toBe(false) |
| 38 | + expect(isComment({})).toBe(false) |
| 39 | + expect(isComment([])).toBe(false) |
| 40 | + }) |
| 41 | +}) |
| 42 | + |
| 43 | +describe('isComponent', () => { |
| 44 | + it('isComponent - b049', () => { |
| 45 | + expect(isComponent(h({}))).toBe(true) |
| 46 | + expect(isComponent(h(() => null))).toBe(true) |
| 47 | + expect(isComponent(h(defineAsyncComponent(() => Promise.resolve({}))))).toBe(true) |
| 48 | + |
| 49 | + expect(isComponent(h('div'))).toBe(false) |
| 50 | + expect(isComponent(createTextVNode('Text'))).toBe(false) |
| 51 | + expect(isComponent(createCommentVNode('Text'))).toBe(false) |
| 52 | + expect(isComponent('')).toBe(false) |
| 53 | + expect(isComponent({})).toBe(false) |
| 54 | + expect(isComponent([])).toBe(false) |
| 55 | + expect(isComponent(null)).toBe(false) |
| 56 | + expect(isComponent(undefined)).toBe(false) |
| 57 | + expect(isComponent(false)).toBe(false) |
| 58 | + expect(isComponent(true)).toBe(false) |
| 59 | + expect(isComponent(0)).toBe(false) |
| 60 | + expect(isComponent(7)).toBe(false) |
| 61 | + }) |
| 62 | +}) |
| 63 | + |
| 64 | +describe('isFunctionalComponent', () => { |
| 65 | + it('isFunctionalComponent - 1af7', () => { |
| 66 | + expect(isFunctionalComponent(h(() => null))).toBe(true) |
| 67 | + |
| 68 | + expect(isFunctionalComponent(h({}))).toBe(false) |
| 69 | + expect(isFunctionalComponent(h(defineAsyncComponent(() => Promise.resolve({}))))).toBe(false) |
| 70 | + expect(isFunctionalComponent(h('div'))).toBe(false) |
| 71 | + expect(isFunctionalComponent(createTextVNode('Text'))).toBe(false) |
| 72 | + expect(isFunctionalComponent(createCommentVNode('Text'))).toBe(false) |
| 73 | + expect(isFunctionalComponent('')).toBe(false) |
| 74 | + expect(isFunctionalComponent({})).toBe(false) |
| 75 | + expect(isFunctionalComponent([])).toBe(false) |
| 76 | + expect(isFunctionalComponent(null)).toBe(false) |
| 77 | + expect(isFunctionalComponent(undefined)).toBe(false) |
| 78 | + expect(isFunctionalComponent(false)).toBe(false) |
| 79 | + expect(isFunctionalComponent(true)).toBe(false) |
| 80 | + expect(isFunctionalComponent(0)).toBe(false) |
| 81 | + expect(isFunctionalComponent(7)).toBe(false) |
| 82 | + }) |
| 83 | +}) |
| 84 | + |
| 85 | +describe('isStatefulComponent', () => { |
| 86 | + it('isStatefulComponent - ecee', () => { |
| 87 | + expect(isStatefulComponent(h({}))).toBe(true) |
| 88 | + expect(isStatefulComponent(h(defineAsyncComponent(() => Promise.resolve({}))))).toBe(true) |
| 89 | + |
| 90 | + expect(isStatefulComponent(h(() => null))).toBe(false) |
| 91 | + expect(isStatefulComponent(h('div'))).toBe(false) |
| 92 | + expect(isStatefulComponent(createTextVNode('Text'))).toBe(false) |
| 93 | + expect(isStatefulComponent(createCommentVNode('Text'))).toBe(false) |
| 94 | + expect(isStatefulComponent('')).toBe(false) |
| 95 | + expect(isStatefulComponent({})).toBe(false) |
| 96 | + expect(isStatefulComponent([])).toBe(false) |
| 97 | + expect(isStatefulComponent(null)).toBe(false) |
| 98 | + expect(isStatefulComponent(undefined)).toBe(false) |
| 99 | + expect(isStatefulComponent(false)).toBe(false) |
| 100 | + expect(isStatefulComponent(true)).toBe(false) |
| 101 | + expect(isStatefulComponent(0)).toBe(false) |
| 102 | + expect(isStatefulComponent(7)).toBe(false) |
| 103 | + }) |
| 104 | +}) |
| 105 | + |
| 106 | +describe('isElement', () => { |
| 107 | + it('isElement - aa0d', () => { |
| 108 | + expect(isElement(h('div'))).toBe(true) |
| 109 | + |
| 110 | + expect(isElement(h({}))).toBe(false) |
| 111 | + expect(isElement(h(() => null))).toBe(false) |
| 112 | + expect(isElement(h(defineAsyncComponent(() => Promise.resolve({}))))).toBe(false) |
| 113 | + expect(isElement(createTextVNode('Text'))).toBe(false) |
| 114 | + expect(isElement(createCommentVNode('Text'))).toBe(false) |
| 115 | + expect(isElement(createVNode(Fragment, null, [h('div')]))).toBe(false) |
| 116 | + expect(isElement('')).toBe(false) |
| 117 | + expect(isElement('string')).toBe(false) |
| 118 | + expect(isElement({})).toBe(false) |
| 119 | + expect(isElement([])).toBe(false) |
| 120 | + expect(isElement(null)).toBe(false) |
| 121 | + expect(isElement(undefined)).toBe(false) |
| 122 | + expect(isElement(false)).toBe(false) |
| 123 | + expect(isElement(true)).toBe(false) |
| 124 | + expect(isElement(0)).toBe(false) |
| 125 | + expect(isElement(7)).toBe(false) |
| 126 | + }) |
| 127 | +}) |
| 128 | + |
| 129 | +describe('isFragment', () => { |
| 130 | + it('isFragment - d88b', () => { |
| 131 | + expect(isFragment([])).toBe(true) |
| 132 | + expect(isFragment(createVNode(Fragment, null, []))).toBe(true) |
| 133 | + |
| 134 | + expect(isFragment(h({}))).toBe(false) |
| 135 | + expect(isFragment(h(() => null))).toBe(false) |
| 136 | + expect(isFragment(h(defineAsyncComponent(() => Promise.resolve({}))))).toBe(false) |
| 137 | + expect(isFragment(h('div'))).toBe(false) |
| 138 | + expect(isFragment(h('div', null, []))).toBe(false) |
| 139 | + expect(isFragment(createTextVNode('Text'))).toBe(false) |
| 140 | + expect(isFragment(createCommentVNode('Text'))).toBe(false) |
| 141 | + expect(isFragment('')).toBe(false) |
| 142 | + expect(isFragment('string')).toBe(false) |
| 143 | + expect(isFragment({})).toBe(false) |
| 144 | + expect(isFragment(null)).toBe(false) |
| 145 | + expect(isFragment(undefined)).toBe(false) |
| 146 | + expect(isFragment(false)).toBe(false) |
| 147 | + expect(isFragment(true)).toBe(false) |
| 148 | + expect(isFragment(0)).toBe(false) |
| 149 | + expect(isFragment(7)).toBe(false) |
| 150 | + }) |
| 151 | +}) |
| 152 | + |
| 153 | +describe('isText', () => { |
| 154 | + it('isText - 7952', () => { |
| 155 | + expect(isText('')).toBe(true) |
| 156 | + expect(isText('string')).toBe(true) |
| 157 | + expect(isText(0)).toBe(true) |
| 158 | + expect(isText(7)).toBe(true) |
| 159 | + expect(isText(createTextVNode('Text'))).toBe(true) |
| 160 | + |
| 161 | + expect(isText(h({}))).toBe(false) |
| 162 | + expect(isText(h(() => null))).toBe(false) |
| 163 | + expect(isText(h(defineAsyncComponent(() => Promise.resolve({}))))).toBe(false) |
| 164 | + expect(isText(h('div'))).toBe(false) |
| 165 | + expect(isText(h('div', null, []))).toBe(false) |
| 166 | + expect(isText(createCommentVNode('Text'))).toBe(false) |
| 167 | + expect(isText(createVNode(Fragment, null, []))).toBe(false) |
| 168 | + expect(isText({})).toBe(false) |
| 169 | + expect(isText([])).toBe(false) |
| 170 | + expect(isText(null)).toBe(false) |
| 171 | + expect(isText(undefined)).toBe(false) |
| 172 | + expect(isText(false)).toBe(false) |
| 173 | + expect(isText(true)).toBe(false) |
| 174 | + }) |
| 175 | +}) |
| 176 | + |
| 177 | +describe('isStatic', () => { |
| 178 | + it('isStatic - aabf', () => { |
| 179 | + expect(isStatic(createStaticVNode('<div></div>', 1))).toBe(true) |
| 180 | + |
| 181 | + expect(isStatic(h({}))).toBe(false) |
| 182 | + expect(isStatic(h(() => null))).toBe(false) |
| 183 | + expect(isStatic(h(defineAsyncComponent(() => Promise.resolve({}))))).toBe(false) |
| 184 | + expect(isStatic(h('div'))).toBe(false) |
| 185 | + expect(isStatic(h('div', null, []))).toBe(false) |
| 186 | + expect(isStatic(createTextVNode('Text'))).toBe(false) |
| 187 | + expect(isStatic(createCommentVNode('Text'))).toBe(false) |
| 188 | + expect(isStatic(createVNode(Fragment, null, []))).toBe(false) |
| 189 | + expect(isStatic('')).toBe(false) |
| 190 | + expect(isStatic('string')).toBe(false) |
| 191 | + expect(isStatic({})).toBe(false) |
| 192 | + expect(isStatic([])).toBe(false) |
| 193 | + expect(isStatic(null)).toBe(false) |
| 194 | + expect(isStatic(undefined)).toBe(false) |
| 195 | + expect(isStatic(false)).toBe(false) |
| 196 | + expect(isStatic(true)).toBe(false) |
| 197 | + expect(isStatic(0)).toBe(false) |
| 198 | + expect(isStatic(7)).toBe(false) |
| 199 | + }) |
| 200 | +}) |
| 201 | + |
| 202 | +describe('getText', () => { |
| 203 | + it('getText - 50eb', () => { |
| 204 | + expect(getText('')).toBe('') |
| 205 | + expect(getText('Text')).toBe('Text') |
| 206 | + expect(getText(0)).toBe('0') |
| 207 | + expect(getText(7)).toBe('7') |
| 208 | + expect(getText(createTextVNode('Text'))).toBe('Text') |
| 209 | + |
| 210 | + expect(getText(null as any)).toBe(undefined) |
| 211 | + expect(getText(undefined as any)).toBe(undefined) |
| 212 | + expect(getText({} as any)).toBe(undefined) |
| 213 | + expect(getText([] as any)).toBe(undefined) |
| 214 | + expect(getText(true as any)).toBe(undefined) |
| 215 | + expect(getText(false as any)).toBe(undefined) |
| 216 | + expect(getText(h('div'))).toBe(undefined) |
| 217 | + expect(getText(h({}))).toBe(undefined) |
| 218 | + }) |
| 219 | +}) |
| 220 | + |
| 221 | +describe('getType', () => { |
| 222 | + it('getType - ba43', () => { |
| 223 | + expect(getType(h({}))).toBe('component') |
| 224 | + expect(getType(h(() => null))).toBe('component') |
| 225 | + expect(getType(h(defineAsyncComponent(() => Promise.resolve({}))))).toBe('component') |
| 226 | + expect(getType(h('div'))).toBe('element') |
| 227 | + expect(getType(h('div', null, []))).toBe('element') |
| 228 | + expect(getType(createTextVNode('Text'))).toBe('text') |
| 229 | + expect(getType(createCommentVNode('Text'))).toBe('comment') |
| 230 | + expect(getType(createVNode(Fragment, null, []))).toBe('fragment') |
| 231 | + expect(getType(createStaticVNode('<div></div>', 1))).toBe('static') |
| 232 | + expect(getType('')).toBe('text') |
| 233 | + expect(getType('string')).toBe('text') |
| 234 | + expect(getType({})).toBe(undefined) |
| 235 | + expect(getType([])).toBe('fragment') |
| 236 | + expect(getType(null)).toBe('comment') |
| 237 | + expect(getType(undefined)).toBe('comment') |
| 238 | + expect(getType(false)).toBe('comment') |
| 239 | + expect(getType(true)).toBe('comment') |
| 240 | + expect(getType(0)).toBe('text') |
| 241 | + expect(getType(7)).toBe('text') |
| 242 | + expect(getType(Fragment)).toBe(undefined) |
| 243 | + expect(getType(Text)).toBe(undefined) |
| 244 | + }) |
| 245 | +}) |
0 commit comments