-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Direction Package Test (#273)
* direction component unit test * direction package test completed * typecheck fixed
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |