Skip to content
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
23 changes: 23 additions & 0 deletions e2e/2.x/basic/components/ScriptAndScriptSetup.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<div>
<button @click="increase">Products: {{ products }}</button>
<Basic />
<span>{{ msg }}</span>
</div>
</template>

<script>
import Basic from './Basic.vue'
</script>

<script setup>
import { ref } from 'vue'

const products = ref(10)
const greet = () => console.log('greet')
const increase = () => {
greet()
num.value++
}
const msg = 'hello world'
</script>
7 changes: 7 additions & 0 deletions e2e/2.x/basic/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Jsx from './components/Jsx.vue'
import Constructor from './components/Constructor.vue'
import { compileStyle } from '@vue/component-compiler-utils'
import ScriptSetup from './components/ScriptSetup'
import ScriptAndScriptSetup from './components/ScriptAndScriptSetup'
import ExtendedTsConfig from './components/ExtendedTsConfig.vue'

jest.mock('@vue/component-compiler-utils', () => ({
Expand Down Expand Up @@ -165,6 +166,12 @@ test('processes SFC with <script setup>', () => {
expect(wrapper.html()).toContain('Welcome to Your Vue.js App')
})

test('processes SFC with both <script> and <script setup> in same component file', () => {
const wrapper = mount(ScriptAndScriptSetup)
expect(wrapper.html()).toContain('Products: 10')
expect(wrapper.html()).toContain('Welcome to Your Vue.js App')
})

test('handles extended tsconfig.json files', () => {
const wrapper = mount(ExtendedTsConfig)
expect(wrapper.element.tagName).toBe('DIV')
Expand Down
9 changes: 7 additions & 2 deletions packages/vue2-jest/lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,20 @@ module.exports = function(src, filename, config) {
})

const templateResult = processTemplate(descriptor, filename, config)
const scriptResult = processScript(descriptor.script, filename, config)
const scriptSetupResult = processScriptSetup(descriptor, filename, config)
const stylesResult = processStyle(descriptor.styles, filename, config)
const customBlocksResult = processCustomBlocks(
descriptor.customBlocks,
filename,
config
)

let scriptResult
const scriptSetupResult = processScriptSetup(descriptor, filename, config)

if (!scriptSetupResult) {
scriptResult = processScript(descriptor.script, filename, config)
}

const isFunctional =
(descriptor.template &&
descriptor.template.attrs &&
Expand Down