Skip to content

Commit

Permalink
improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bhushankhope committed Apr 15, 2024
1 parent 01cb443 commit 33215da
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ const enum DefType {
NamespacedNamedUrl = Url | Named | Namespaced,
}

/**
* Throws the error if value is empty else returns value
*/
function throwIfEmpty<T>(value: T | undefined): T {
/* istanbul ignore if */
if (value === undefined) {
throw new Error('empty value');
}

return value;
}

/**
* Type for the values of registry dispatch table object.
*/
Expand All @@ -62,18 +74,19 @@ type RegistryDispatcher = (reg: MatIconRegistry, resource: SafeValue, def: BaseS
*/
const REGISTRY_DISPATCH_TABLE: Record<DefType, RegistryDispatcher> = {
[DefType.Url]: (reg, url, { options }) => reg.addSvgIconSet(url, options),
[DefType.NamedUrl]: (reg, url, { name, options }) => reg.addSvgIcon(name ?? '', url, options),
[DefType.NamedUrl]: (reg, url, { name, options }) => reg.addSvgIcon(throwIfEmpty(name), url, options),
[DefType.NamespacedUrl]: (reg, url, { namespace, options }) =>
reg.addSvgIconSetInNamespace(namespace ?? '', url, options),
reg.addSvgIconSetInNamespace(throwIfEmpty(namespace), url, options),
[DefType.NamespacedNamedUrl]: (reg, url, { name, namespace, options }) =>
reg.addSvgIconInNamespace(namespace ?? '', name ?? '', url, options),
reg.addSvgIconInNamespace(throwIfEmpty(namespace), throwIfEmpty(name), url, options),

[DefType.Literal]: (reg, literal, { options }) => reg.addSvgIconSetLiteral(literal, options),
[DefType.NamedLiteral]: (reg, literal, { name, options }) => reg.addSvgIconLiteral(name ?? '', literal, options),
[DefType.NamedLiteral]: (reg, literal, { name, options }) =>
reg.addSvgIconLiteral(throwIfEmpty(name), literal, options),
[DefType.NamespacedLiteral]: (reg, literal, { namespace, options }) =>
reg.addSvgIconSetLiteralInNamespace(namespace ?? '', literal, options),
reg.addSvgIconSetLiteralInNamespace(throwIfEmpty(namespace), literal, options),
[DefType.NamespacedNamedLiteral]: (reg, literal, { name, namespace, options }) =>
reg.addSvgIconLiteralInNamespace(namespace ?? '', name ?? '', literal, options),
reg.addSvgIconLiteralInNamespace(throwIfEmpty(namespace), throwIfEmpty(name), literal, options),
};

/**
Expand Down

0 comments on commit 33215da

Please sign in to comment.