Skip to content

Commit

Permalink
test: add element-plus resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Oct 18, 2021
1 parent f55121a commit 77940ba
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/resolvers/__snapshots__/element-plus.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Element Plus Resolver components and directives should be transformed 1`] = `
Object {
"code": "/* unplugin-vue-components disabled */import { ElButton as __unplugin_components_0 } from 'element-plus/es';import 'element-plus/es/components/button/style/css';
(_ctx, _cache) => {
const _component_el_button = __unplugin_components_0
const _directive_loading = _resolveDirective(\\"loading\\")
return (_openBlock(), _createElementBlock(_Fragment, null, [
_createVNode(_component_el_button, null, {
default: _withCtx(() => [
_hoisted_1
]),
_: 1 /* STABLE */
}),
_withDirectives(_createElementVNode(\\"div\\", null, null, 512 /* NEED_PATCH */), [
[_directive_loading, true]
])
], 64 /* STABLE_FRAGMENT */))
}
",
}
`;
33 changes: 33 additions & 0 deletions test/resolvers/element-plus.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ElementPlusResolver } from '../../src/resolvers'
import { Context } from '../../src/core/context'

describe('Element Plus Resolver', () => {
it('components and directives should be transformed', async() => {
const code = `
(_ctx, _cache) => {
const _component_el_button = _resolveComponent("el-button")
const _directive_loading = _resolveDirective("loading")
return (_openBlock(), _createElementBlock(_Fragment, null, [
_createVNode(_component_el_button, null, {
default: _withCtx(() => [
_hoisted_1
]),
_: 1 /* STABLE */
}),
_withDirectives(_createElementVNode("div", null, null, 512 /* NEED_PATCH */), [
[_directive_loading, true]
])
], 64 /* STABLE_FRAGMENT */))
}
`

const ctx = new Context({
resolvers: [ElementPlusResolver({})],
transformer: 'vue3',
directives: true,
})
ctx.sourcemap = false
expect(await ctx.transform(code, '')).toMatchSnapshot()
})
})

0 comments on commit 77940ba

Please sign in to comment.