Skip to content

chore: use experimentalExposeScriptSetupContext for vue-tsc #1170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions tests/emit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
DefineComponent,
defineComponent,
FunctionalComponent,
getCurrentInstance,
Expand Down Expand Up @@ -346,16 +345,23 @@ describe('emitted', () => {
expect(wrapper.emitted('click')).toHaveLength(1)
})

it.each([EmitsEventSFC, EmitsEventScriptSetup] as DefineComponent[])(
'captures emitted events',
async (component) => {
const wrapper = mount(component)
await wrapper.trigger('click')
it('captures emitted events in SFC', async () => {
const wrapper = mount(EmitsEventSFC)
await wrapper.trigger('click')

expect(wrapper.emitted().click).toHaveLength(1)
expect(wrapper.emitted().bar).toHaveLength(2)
expect(wrapper.emitted().bar[0]).toEqual(['mounted'])
expect(wrapper.emitted().bar[1]).toEqual(['click'])
}
)
expect(wrapper.emitted().click).toHaveLength(1)
expect(wrapper.emitted().bar).toHaveLength(2)
expect(wrapper.emitted().bar[0]).toEqual(['mounted'])
expect(wrapper.emitted().bar[1]).toEqual(['click'])
})

it('captures emitted events in script setup', async () => {
const wrapper = mount(EmitsEventScriptSetup)
await wrapper.trigger('click')

expect(wrapper.emitted().click).toHaveLength(1)
expect(wrapper.emitted().bar).toHaveLength(2)
expect(wrapper.emitted().bar[0]).toEqual(['mounted'])
expect(wrapper.emitted().bar[1]).toEqual(['click'])
})
})
3 changes: 2 additions & 1 deletion tests/expose.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ describe('expose', () => {
const wrapper = mount(DefineExposeWithRenderFunction)

// other is exposed vie `expose`
// @ts-ignore upstream issue, see https://github.com/vuejs/vue-next/issues/4397#issuecomment-957613874
expect(wrapper.vm.other).toBe('other')
// can't access `msg` as it is not exposed
// and we are in a component with a setup returning a render function
expect(wrapper.vm.msg).toBeUndefined()
expect((wrapper.vm as unknown as { msg: undefined }).msg).toBeUndefined()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be ts-ignoring these or is there more work to come (maybe in Volar) before merging this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is expected to not compile without as, as the test is just to check it is not exposed 😉 So I think it's fine to explicitly cast it to make TS happy.

})

it('access vm with <script setup> and defineExpose()', async () => {
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"tests",
"src",
"types"
]
],
"vueCompilerOptions": {
"experimentalExposeScriptSetupContext": true
}
}
3 changes: 1 addition & 2 deletions tsconfig.volar.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"compilerOptions": {
"lib": ["DOM", "ES2020"],
"skipLibCheck": true
},
"exclude": ["tests/expose.spec.ts"]
}
}