-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
d03b02f
commit 9356bb8
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
crates/fervid_napi/__tests__/__snapshots__/defineExpose.spec.ts.snap
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,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 | ||
}); | ||
} | ||
}; | ||
" | ||
`; |
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,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) | ||
}) |