-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for
usePropagateScopesToAllRoots
(#10226)
Added missing test for `usePropagateScopesToAllRoots` that was added in #10172. Also testing against the default Vue behavior, since it is possible that a future update will make the workaround obsolete.
- Loading branch information
Showing
3 changed files
with
76 additions
and
27 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
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,58 @@ | ||
/* eslint-disable vue/one-component-per-file */ | ||
import { mount } from '@vue/test-utils' | ||
import { describe, expect, test } from 'vitest' | ||
import { defineComponent } from 'vue' | ||
import { usePropagateScopesToAllRoots } from '../patching' | ||
|
||
describe('usePropagateScopesToAllRoots', () => { | ||
function makeComponents(doPropagate: boolean) { | ||
const InnerComponent = defineComponent({ | ||
template: '<div class="inner"></div>', | ||
__scopeId: 'inner', | ||
}) | ||
|
||
const WrapperComponent = defineComponent({ | ||
setup() { | ||
if (doPropagate) usePropagateScopesToAllRoots() | ||
}, | ||
template: '<slot />', | ||
__scopeId: 'wrapper', | ||
}) | ||
|
||
const WrappingComponent = defineComponent({ | ||
components: { Inner: InnerComponent, Wrapper: WrapperComponent }, | ||
template: '<Wrapper><Inner /></Wrapper>', | ||
__scopeId: 'wrapping', | ||
}) | ||
|
||
const OuterComponent = defineComponent({ | ||
components: { Wrapping: WrappingComponent }, | ||
template: '<Wrapping />', | ||
__scopeId: 'outer', | ||
}) | ||
return { InnerComponent, OuterComponent } | ||
} | ||
|
||
test('scopes propagate through wrapper root slot', () => { | ||
const { InnerComponent, OuterComponent } = makeComponents(true) | ||
const outer = mount(OuterComponent) | ||
expect(outer.findComponent(InnerComponent).element.getAttributeNames()).toEqual([ | ||
'inner', | ||
'wrapping', | ||
'wrapper-s', | ||
'outer', | ||
'class', | ||
]) | ||
}) | ||
|
||
test('manual propagation required', () => { | ||
const { InnerComponent, OuterComponent } = makeComponents(false) | ||
const outer = mount(OuterComponent) | ||
expect(outer.findComponent(InnerComponent).element.getAttributeNames()).toEqual([ | ||
'inner', | ||
'wrapping', | ||
'wrapper-s', | ||
'class', | ||
]) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.