diff --git a/packages/x-components/src/components/result/__tests__/result-variants-provider-and-selector.spec.ts b/packages/x-components/src/components/result/__tests__/result-variants-provider-and-selector.spec.ts
index cb73fa1157..8d7a8dd5d9 100644
--- a/packages/x-components/src/components/result/__tests__/result-variants-provider-and-selector.spec.ts
+++ b/packages/x-components/src/components/result/__tests__/result-variants-provider-and-selector.spec.ts
@@ -4,7 +4,7 @@ import { createResultStub } from '../../../__stubs__/index';
import { findTestDataById, getDataTestSelector, installNewXPlugin } from '../../../__tests__/utils';
import ResultVariantsProvider from '../result-variants-provider.vue';
import ResultVariantSelector from '../result-variant-selector.vue';
-import { XPlugin } from '../../../plugins/index';
+import { bus } from '../../../plugins/index';
const variants = [
{
@@ -51,8 +51,7 @@ const renderResultVariantsProvider = ({
autoSelectDepth
}: ResultVariantsProviderOptions): ResultVariantsProviderApi => {
const [, localVue] = installNewXPlugin();
-
- const eventsBusSpy = jest.spyOn(XPlugin.bus, 'emit');
+ const eventsBusSpy = jest.spyOn(bus, 'emit');
const wrapper = mount(
{
@@ -105,6 +104,10 @@ const renderResultVariantsProvider = ({
};
describe('results with variants', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
it('provider exposes the result in the default slot', () => {
const template = `
{{newResult.name}}
@@ -349,7 +352,7 @@ describe('results with variants', () => {
it('wont render if no result is injected', () => {
const { wrapper } = renderResultVariantsProvider({
- result: null
+ result: {}
});
expect(wrapper.find(getDataTestSelector('variants-list')).exists()).toBe(false);
@@ -450,7 +453,7 @@ describe('results with variants', () => {
*/
interface ResultVariantsProviderOptions {
/** The result containing the variants. */
- result: Result | null;
+ result: Result | Record;
/** The template to render inside the provider's default slot. */
template?: string;
/** Indicates the number of levels to auto select the first variants. */
@@ -485,7 +488,7 @@ interface ResultVariantsProviderApi {
*/
setResult: (result: Result) => Promise;
/**
- * A Jest spy set in the {@link XPlugin} bus `emit` function,
+ * A Jest spy set in the {@link bus} bus `emit` function,
* useful to test events emitted in the first lifecycle hooks of the component.
*/
eventsBusSpy: jest.SpyInstance;
diff --git a/packages/x-components/src/components/result/result-variant-selector.vue b/packages/x-components/src/components/result/result-variant-selector.vue
index 6bc877239c..445bb66174 100644
--- a/packages/x-components/src/components/result/result-variant-selector.vue
+++ b/packages/x-components/src/components/result/result-variant-selector.vue
@@ -85,7 +85,7 @@
* @public
* @returns The 'selectResultVariant' injection key.
*/
- const selectResultVariant = inject[ void>>(
+ const selectResultVariant = inject<(variant: ResultVariant, level?: number) => void>(
SELECT_RESULT_VARIANT_KEY as string
);
@@ -111,9 +111,9 @@
*/
const variants = computed(() => {
if (props.level === 0) {
- return result?.value?.variants;
+ return result!.value?.variants;
}
- return selectedVariants?.value[props.level - 1]?.variants;
+ return selectedVariants!.value[props.level - 1]?.variants;
});
/**
@@ -133,7 +133,7 @@
* @internal
*/
const selectVariant = (variant: ResultVariant): void => {
- selectResultVariant!.value(variant, props.level);
+ selectResultVariant!(variant, props.level);
};
/**
diff --git a/packages/x-components/src/components/result/result-variants-provider.vue b/packages/x-components/src/components/result/result-variants-provider.vue
index 4ea48d4e5b..12814b4133 100644
--- a/packages/x-components/src/components/result/result-variants-provider.vue
+++ b/packages/x-components/src/components/result/result-variants-provider.vue
@@ -1,13 +1,22 @@
]