1
0
mirror of https://github.com/robonen/tools.git synced 2026-03-20 10:54:44 +00:00

feat(packages/vue): add useContextFactory composable

This commit is contained in:
2024-10-20 06:44:19 +07:00
parent aff1a95c2f
commit 8989701303
2 changed files with 5 additions and 5 deletions

View File

@@ -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);

View File

@@ -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