Skip to content

Commit

Permalink
fix(core): Allow arrays of plugins on usePlugin(..) (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseLion authored Jan 26, 2024
1 parent ea8cc18 commit 7dcef4c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 7 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ export {
};

/**
* Extends `@assertive-ts/core` with a local or 3rd-party plugin.
* Extends `@assertive-ts/core` with local or 3rd-party plugin(s).
*
* @param plugin the plugin to use to extend assertive-ts
* @param plugins a plugin or an array of plugins to use
* @see {@link Plugin Plugin}
*/
export function usePlugin<T, A extends Assertion<T>>(plugin: Plugin<T, A>): void {
config.addPlugin(plugin);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function usePlugin<P extends Plugin<any, Assertion<any>>>(plugins: P | P[]): void {
Array.isArray(plugins)
? plugins.forEach(plugin => config.addPlugin(plugin))
: config.addPlugin(plugins);
}
8 changes: 7 additions & 1 deletion packages/core/src/lib/config/Config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Assertion } from "../Assertion";

/**
* A plugin object that can be used to extend the `expect(..)` function.
*
* @param T the type the plugin is meant for
* @param A the type of the assertion for `T`
*/
export interface Plugin<T, A extends Assertion<T>> {
/**
* The `Assertion<T>` instance the plugin adds
* The assertion `A` constructor the plugin adds
*/
Assertion: new(actual: T) => A;
/**
Expand Down

0 comments on commit 7dcef4c

Please sign in to comment.