-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runtime-vapor): implement expose (#181)
Co-authored-by: Kevin Deng 三咲智子 <sxzz@sxzz.moe>
- Loading branch information
Showing
2 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { describe, expect } from 'vitest' | ||
import { makeRender } from './_utils' | ||
import { type Ref, ref } from '@vue/reactivity' | ||
|
||
const define = makeRender() | ||
|
||
describe('component expose', () => { | ||
test('should work', async () => { | ||
const expxosedObj = { foo: 1 } | ||
const { render } = define({ | ||
setup(_, { expose }) { | ||
expose(expxosedObj) | ||
}, | ||
}) | ||
const { instance } = render() | ||
expect(instance.exposed).toEqual(expxosedObj) | ||
}) | ||
|
||
test('should warn when called multiple times', async () => { | ||
const { render } = define({ | ||
setup(_, { expose }) { | ||
expose() | ||
expose() | ||
}, | ||
}) | ||
render() | ||
expect( | ||
'expose() should be called only once per setup().', | ||
).toHaveBeenWarned() | ||
}) | ||
|
||
test('should warn when passed non-object', async () => { | ||
const exposedRef = ref<number[] | Ref>([1, 2, 3]) | ||
const { render } = define({ | ||
setup(_, { expose }) { | ||
expose(exposedRef.value) | ||
}, | ||
}) | ||
render() | ||
expect( | ||
'expose() should be passed a plain object, received array.', | ||
).toHaveBeenWarned() | ||
exposedRef.value = ref(1) | ||
render() | ||
expect( | ||
'expose() should be passed a plain object, received ref.', | ||
).toHaveBeenWarned() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters