-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow to mock global function in script setup components (#1871)
Fixes #1869
- Loading branch information
Showing
8 changed files
with
114 additions
and
14 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
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
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,16 @@ | ||
<script lang="ts"> | ||
import { defineComponent } from 'vue' | ||
export default defineComponent({ | ||
data() { | ||
return { hello: 'hello' } | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div>{{ hello }}</div> | ||
<!-- this emulates components that use a global function like $t for i18n --> | ||
<!-- this function can be mocked using global.mocks --> | ||
<div>{{ $t('world') }}</div> | ||
</template> |
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,17 @@ | ||
<script setup lang="ts"> | ||
import { computed, ref } from 'vue' | ||
const props = defineProps<{ count: number }>() | ||
const times = ref(2) | ||
const result = computed(() => props.count * times.value) | ||
defineExpose(props) | ||
</script> | ||
|
||
<template> | ||
<div>{{ count }} x {{ times }} = {{ result }}</div> | ||
<button @click="times += 1"> | ||
x1 | ||
</button> | ||
</template> |
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,11 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
const hello = ref('hello') | ||
</script> | ||
|
||
<template> | ||
<div>{{ hello }}</div> | ||
<!-- this emulates components that use a global function like $t for i18n --> | ||
<!-- this function can be mocked using global.mocks --> | ||
<div>{{ $t('world') }}</div> | ||
</template> |
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
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
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