Skip to content

Commit 7dcef4c

Browse files
authored
fix(core): Allow arrays of plugins on usePlugin(..) (#116)
1 parent ea8cc18 commit 7dcef4c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/core/src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ export {
2020
};
2121

2222
/**
23-
* Extends `@assertive-ts/core` with a local or 3rd-party plugin.
23+
* Extends `@assertive-ts/core` with local or 3rd-party plugin(s).
2424
*
25-
* @param plugin the plugin to use to extend assertive-ts
25+
* @param plugins a plugin or an array of plugins to use
2626
* @see {@link Plugin Plugin}
2727
*/
28-
export function usePlugin<T, A extends Assertion<T>>(plugin: Plugin<T, A>): void {
29-
config.addPlugin(plugin);
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
29+
export function usePlugin<P extends Plugin<any, Assertion<any>>>(plugins: P | P[]): void {
30+
Array.isArray(plugins)
31+
? plugins.forEach(plugin => config.addPlugin(plugin))
32+
: config.addPlugin(plugins);
3033
}

packages/core/src/lib/config/Config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { Assertion } from "../Assertion";
22

3+
/**
4+
* A plugin object that can be used to extend the `expect(..)` function.
5+
*
6+
* @param T the type the plugin is meant for
7+
* @param A the type of the assertion for `T`
8+
*/
39
export interface Plugin<T, A extends Assertion<T>> {
410
/**
5-
* The `Assertion<T>` instance the plugin adds
11+
* The assertion `A` constructor the plugin adds
612
*/
713
Assertion: new(actual: T) => A;
814
/**

0 commit comments

Comments
 (0)