|
2 | 2 | type CompilerOptions,
|
3 | 3 | type ElementNode,
|
4 | 4 | ElementTypes,
|
| 5 | + ErrorCodes, |
5 | 6 | type IfBranchNode,
|
6 | 7 | type IfNode,
|
7 | 8 | NodeTypes,
|
@@ -190,6 +191,28 @@ describe('compiler: v-skip', () => {
|
190 | 191 | expect(generate(root).code).toMatchSnapshot()
|
191 | 192 | })
|
192 | 193 |
|
| 194 | + test('v-skip with key', () => { |
| 195 | + const { root, node } = parseWithSkipTransform( |
| 196 | + `<div v-skip="nested" key="foo"/>`, |
| 197 | + ) |
| 198 | + expect(node.type).toBe(NodeTypes.SKIP) |
| 199 | + expect((node.test as SimpleExpressionNode).content).toBe(`_ctx.nested`) |
| 200 | + expect(node.consequent.type === NodeTypes.JS_CALL_EXPRESSION).toBe(true) |
| 201 | + expect(node.alternate.children.length).toBe(1) |
| 202 | + expect(node.alternate.children[0].type).toBe(NodeTypes.ELEMENT) |
| 203 | + expect((node.alternate.children[0] as ElementNode).tag).toBe(`div`) |
| 204 | + expect( |
| 205 | + (node.alternate.children[0] as ElementNode).props[0], |
| 206 | + ).toMatchObject({ |
| 207 | + name: 'key', |
| 208 | + type: NodeTypes.ATTRIBUTE, |
| 209 | + value: { |
| 210 | + content: 'foo', |
| 211 | + }, |
| 212 | + }) |
| 213 | + expect(generate(root).code).toMatchSnapshot() |
| 214 | + }) |
| 215 | + |
193 | 216 | test('v-else + v-skip', () => {
|
194 | 217 | const { root, node } = parseWithSkipTransform(
|
195 | 218 | `<div v-if="ok"/><div v-else v-skip="nested"/>`,
|
@@ -338,5 +361,63 @@ describe('compiler: v-skip', () => {
|
338 | 361 | })
|
339 | 362 | })
|
340 | 363 |
|
341 |
| - describe.todo('errors', () => {}) |
| 364 | + describe('errors', () => { |
| 365 | + test('no expression', () => { |
| 366 | + const onError = vi.fn() |
| 367 | + const { node } = parseWithSkipTransform(`<div v-skip/>`, { onError }) |
| 368 | + expect(onError.mock.calls[0]).toMatchObject([ |
| 369 | + { |
| 370 | + code: ErrorCodes.X_V_SKIP_NO_EXPRESSION, |
| 371 | + loc: node.loc, |
| 372 | + }, |
| 373 | + ]) |
| 374 | + }) |
| 375 | + |
| 376 | + test('on <slot>', () => { |
| 377 | + const onError = vi.fn() |
| 378 | + parseWithSkipTransform(`<slot v-skip="ok"/>`, { onError }) |
| 379 | + expect(onError.mock.calls[0]).toMatchObject([ |
| 380 | + { |
| 381 | + code: ErrorCodes.X_V_SKIP_ON_TEMPLATE, |
| 382 | + }, |
| 383 | + ]) |
| 384 | + }) |
| 385 | + |
| 386 | + test('on <template>', () => { |
| 387 | + const onError = vi.fn() |
| 388 | + parseWithSkipTransform(`<template v-skip="ok"/>`, { onError }) |
| 389 | + expect(onError.mock.calls[0]).toMatchObject([ |
| 390 | + { |
| 391 | + code: ErrorCodes.X_V_SKIP_ON_TEMPLATE, |
| 392 | + }, |
| 393 | + ]) |
| 394 | + }) |
| 395 | + |
| 396 | + test('on component without default slot', () => { |
| 397 | + const onError = vi.fn() |
| 398 | + parseWithSkipTransform( |
| 399 | + `<Comp v-skip="ok"> |
| 400 | + <template #foo>foo</template> |
| 401 | + </Comp>`, |
| 402 | + { onError }, |
| 403 | + ) |
| 404 | + expect(onError.mock.calls[0]).toMatchObject([ |
| 405 | + { |
| 406 | + code: ErrorCodes.X_V_SKIP_UNEXPECTED_SLOT, |
| 407 | + }, |
| 408 | + ]) |
| 409 | + }) |
| 410 | + |
| 411 | + test('with v-for', () => { |
| 412 | + const onError = vi.fn() |
| 413 | + parseWithSkipTransform(`<div v-for="i in items" v-skip="ok"/>`, { |
| 414 | + onError, |
| 415 | + }) |
| 416 | + expect(onError.mock.calls[0]).toMatchObject([ |
| 417 | + { |
| 418 | + code: ErrorCodes.X_V_SKIP_WITH_V_FOR, |
| 419 | + }, |
| 420 | + ]) |
| 421 | + }) |
| 422 | + }) |
342 | 423 | })
|
0 commit comments