Skip to content

Commit

Permalink
test(#42): add defineExpose tests (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix-ru authored Nov 2, 2024
1 parent d03b02f commit 9356bb8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`<script> after <script setup> the script content not end with \`\\n\` 1`] = `
"const n = 1;
import { x } from './x';
export default {
__name: "anonymous",
setup (__props, { expose: __expose }) {
__expose();
return {
n,
get x () {
return x;
}
};
}
};
"
`;
exports[`defineExpose() 1`] = `
"export default {
__name: "anonymous",
setup (__props, { expose: __expose }) {
__expose({
foo: 123
});
}
};
"
`;
30 changes: 30 additions & 0 deletions crates/fervid_napi/__tests__/defineExpose.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect, test } from 'vitest'
import { assertCode, compile } from './utils'

test('defineExpose()', () => {
const { content } = compile(`
<script setup>
defineExpose({ foo: 123 })
</script>
`)
assertCode(content)
// should remove defineOptions import and call
expect(content).not.toMatch('defineExpose')
// should generate correct setup signature
expect(content).toMatch(`setup (__props, { expose: __expose }) {`)
// should replace callee
expect(content).toMatch(`
__expose({
foo: 123
})`)
})

test('<script> after <script setup> the script content not end with `\\n`', () => {
const { content } = compile(`
<script setup>
import { x } from './x'
</script>
<script>const n = 1</script>
`)
assertCode(content)
})

0 comments on commit 9356bb8

Please sign in to comment.