Skip to content

Commit

Permalink
test: add
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Oct 5, 2022
1 parent 5ad8f0c commit f9512aa
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Expand Up @@ -341,6 +341,42 @@ defineExpose({ foo: 123 })
content.lastIndexOf(`import { x }`)
)
})

describe('import ref/reactive function from other place', () => {
test('import directly', () => {
const { bindings } = compile(`
<script setup>
import { ref, reactive } from './foo'
const foo = ref(1)
const bar = reactive(1)
</script>
`)
expect(bindings).toStrictEqual({
ref: BindingTypes.SETUP_MAYBE_REF,
reactive: BindingTypes.SETUP_MAYBE_REF,
foo: BindingTypes.SETUP_MAYBE_REF,
bar: BindingTypes.SETUP_MAYBE_REF
})
})

test('import w/ alias', () => {
const { bindings } = compile(`
<script setup>
import { ref as _ref, reactive as _reactive } from './foo'
const foo = ref(1)
const bar = reactive(1)
</script>
`)
expect(bindings).toStrictEqual({
_reactive: BindingTypes.SETUP_MAYBE_REF,
_ref: BindingTypes.SETUP_MAYBE_REF,
foo: BindingTypes.SETUP_REF,
bar: BindingTypes.SETUP_REACTIVE_CONST
})
})
})
})

// in dev mode, declared bindings are returned as an object from setup()
Expand Down

0 comments on commit f9512aa

Please sign in to comment.