|
| 1 | +import type { SetupContext } from '../src/component' |
| 2 | +import { |
| 3 | + createComponent, |
| 4 | + defineComponent, |
| 5 | + ref, |
| 6 | + template, |
| 7 | + useAttrs, |
| 8 | + useSlots, |
| 9 | +} from '../src' |
| 10 | +import { makeRender } from './_utils' |
| 11 | + |
| 12 | +const define = makeRender<any>() |
| 13 | + |
| 14 | +describe('SFC <script setup> helpers', () => { |
| 15 | + test.todo('should warn runtime usage', () => {}) |
| 16 | + |
| 17 | + test('useSlots / useAttrs (no args)', () => { |
| 18 | + let slots: SetupContext['slots'] | undefined |
| 19 | + let attrs: SetupContext['attrs'] | undefined |
| 20 | + |
| 21 | + const Comp = { |
| 22 | + setup() { |
| 23 | + slots = useSlots() |
| 24 | + attrs = useAttrs() |
| 25 | + }, |
| 26 | + } |
| 27 | + const count = ref(0) |
| 28 | + const passedAttrs = { id: () => count.value } |
| 29 | + const passedSlots = { |
| 30 | + default: () => template('')(), |
| 31 | + x: () => template('')(), |
| 32 | + } |
| 33 | + |
| 34 | + const { render } = define({ |
| 35 | + render: () => createComponent(Comp, passedAttrs, passedSlots), |
| 36 | + }) |
| 37 | + render() |
| 38 | + |
| 39 | + expect(typeof slots!.default).toBe('function') |
| 40 | + expect(typeof slots!.x).toBe('function') |
| 41 | + expect(attrs).toMatchObject({ id: 0 }) |
| 42 | + |
| 43 | + count.value++ |
| 44 | + expect(attrs).toMatchObject({ id: 1 }) |
| 45 | + }) |
| 46 | + |
| 47 | + test('useSlots / useAttrs (with args)', () => { |
| 48 | + let slots: SetupContext['slots'] | undefined |
| 49 | + let attrs: SetupContext['attrs'] | undefined |
| 50 | + let ctx: SetupContext | undefined |
| 51 | + const Comp = defineComponent({ |
| 52 | + setup(_, _ctx) { |
| 53 | + slots = useSlots() |
| 54 | + attrs = useAttrs() |
| 55 | + ctx = _ctx |
| 56 | + }, |
| 57 | + }) |
| 58 | + const { render } = define({ render: () => createComponent(Comp) }) |
| 59 | + render() |
| 60 | + expect(slots).toBe(ctx!.slots) |
| 61 | + expect(attrs).toBe(ctx!.attrs) |
| 62 | + }) |
| 63 | + |
| 64 | + describe.todo('mergeDefaults', () => { |
| 65 | + test.todo('object syntax', () => {}) |
| 66 | + test.todo('array syntax', () => {}) |
| 67 | + test.todo('merging with skipFactory', () => {}) |
| 68 | + test.todo('should warn missing', () => {}) |
| 69 | + }) |
| 70 | + |
| 71 | + describe('mergeModels', () => { |
| 72 | + test.todo('array syntax', () => {}) |
| 73 | + test.todo('object syntax', () => {}) |
| 74 | + test.todo('overwrite', () => {}) |
| 75 | + }) |
| 76 | + |
| 77 | + test.todo('createPropsRestProxy', () => {}) |
| 78 | + |
| 79 | + describe.todo('withAsyncContext', () => { |
| 80 | + test.todo('basic', async () => {}) |
| 81 | + test.todo('error handling', async () => {}) |
| 82 | + test.todo('should not leak instance on multiple awaits', async () => {}) |
| 83 | + test.todo('should not leak on multiple awaits + error', async () => {}) |
| 84 | + test.todo('race conditions', async () => {}) |
| 85 | + test.todo('should teardown in-scope effects', async () => {}) |
| 86 | + }) |
| 87 | +}) |
0 commit comments