mirror of
https://github.com/robonen/tools.git
synced 2026-03-20 02:44:45 +00:00
feat(packages/vue): add useContextFactory composable
This commit is contained in:
@@ -37,7 +37,7 @@ function testFactory<Data>(
|
|||||||
// TODO: maybe replace template with passing mock functions to setup
|
// TODO: maybe replace template with passing mock functions to setup
|
||||||
|
|
||||||
describe('useContextFactory', () => {
|
describe('useContextFactory', () => {
|
||||||
it('should provide and inject context correctly', () => {
|
it('provide and inject context correctly', () => {
|
||||||
const { Parent } = testFactory('test');
|
const { Parent } = testFactory('test');
|
||||||
|
|
||||||
const component = mount(Parent);
|
const component = mount(Parent);
|
||||||
@@ -45,13 +45,13 @@ describe('useContextFactory', () => {
|
|||||||
expect(component.text()).toBe('test');
|
expect(component.text()).toBe('test');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw an error when context is not provided', () => {
|
it('throw an error when context is not provided', () => {
|
||||||
const { Child } = testFactory('test');
|
const { Child } = testFactory('test');
|
||||||
|
|
||||||
expect(() => mount(Child)).toThrow(VueToolsError);
|
expect(() => mount(Child)).toThrow(VueToolsError);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should inject a fallback value when context is not provided', () => {
|
it('inject a fallback value when context is not provided', () => {
|
||||||
const { Child } = testFactory('test', { fallback: 'fallback' });
|
const { Child } = testFactory('test', { fallback: 'fallback' });
|
||||||
|
|
||||||
const component = mount(Child);
|
const component = mount(Child);
|
||||||
@@ -59,7 +59,7 @@ describe('useContextFactory', () => {
|
|||||||
expect(component.text()).toBe('fallback');
|
expect(component.text()).toBe('fallback');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should correctly handle null values', () => {
|
it('correctly handle null values', () => {
|
||||||
const { Parent } = testFactory(null);
|
const { Parent } = testFactory(null);
|
||||||
|
|
||||||
const component = mount(Parent);
|
const component = mount(Parent);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { inject, provide, type InjectionKey } from 'vue';
|
import { inject, provide, type InjectionKey } from 'vue';
|
||||||
import { VueToolsError } from '../../utils';
|
import { VueToolsError } from '../..';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name useContextFactory
|
* @name useContextFactory
|
||||||
|
|||||||
Reference in New Issue
Block a user