Skip to content

Commit

Permalink
feat(core): Direction Package Test (#273)
Browse files Browse the repository at this point in the history
* direction component unit test

* direction package test completed

* typecheck fixed
  • Loading branch information
wramzo committed Aug 7, 2023
1 parent 6d2a2bb commit b52e436
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions packages/components/direction/src/direction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { describe, expect, it } from 'vitest'
import { mount } from '@vue/test-utils'
import { type Component } from 'vue'
import { DirectionProvider, useDirection } from './Direction'

const DirectionContextSymbol = Symbol('DirectionContext')

describe('direction', () => {
function propsTest(dir: any) {
it(`props ${dir}`, () => {
const wrapper = mount(DirectionProvider, {
props: {
dir,
},
})
expect(wrapper.props().dir).toBe(dir)
})
}

propsTest('ltr')
propsTest('rtl')

it('slot', () => {
const wrapper = mount(DirectionProvider, {
slots: {
default: 'test',
},
})
expect(wrapper.html()).toContain('test')
})
it('provide, inject and slot', () => {
const ChildComponent = {
setup() {
const dir = useDirection()
return {
dir,
}
},
template: '<div>{{ dir }}</div>',
} as Component

const childWrapper = mount(ChildComponent, {
global: {
provide: {
[DirectionContextSymbol]: 'ltr',
},
},
})

const main = {
components: { DirectionProvider, ChildComponent },
template: `
<DirectionProvider dir="ltr">
<ChildComponent />
</DirectionProvider>
`,
} as Component

const wrapper = mount(main, {})
expect(wrapper.html()).toContain('ltr')
expect(childWrapper.html()).toContain('ltr')
})
})

0 comments on commit b52e436

Please sign in to comment.