Skip to content

Commit

Permalink
fix: script and script setup in same vue file (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
renansoares committed Mar 2, 2023
1 parent 3dc76ff commit 36c6d97
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
23 changes: 23 additions & 0 deletions e2e/2.x/basic/components/ScriptAndScriptSetup.vue
@@ -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
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
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

0 comments on commit 36c6d97

Please sign in to comment.