Skip to content

Commit

Permalink
Merge pull request #246 from ilia-marchenko/WAT-3484
Browse files Browse the repository at this point in the history
WAT-3484 Chai plugins injection
  • Loading branch information
ArtMathArt authored Jul 2, 2024
2 parents 4262ce9 + 29ee91f commit 6a2ef52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/async-assert/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ type WrappedPromisedAssertionApi = PromisedAssert & {

export function createAssertion(options: IAssertionOptions = {}) {
const isSoft = options.isSoft === true;
for (const plugin of options.plugins || []) {
chai.use(plugin);
}
// eslint-disable-next-line sonarjs/cognitive-complexity
const proxyGetter = (target, fieldName: string) => {
if (fieldName === errorMessagesField) {
Expand Down
6 changes: 6 additions & 0 deletions core/types/src/async-assert/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import type { use as chaiUse } from 'chai';

type First<T> = T extends [infer A, ...any[]] ? A : never;
type ChaiPlugin = First<Parameters<typeof chaiUse>>;

export interface IAssertionSuccessMeta {
isSoft: boolean;
successMessage?: string;
Expand All @@ -15,4 +20,5 @@ export interface IAssertionOptions {
isSoft?: boolean;
onSuccess?: (IAssertionSuccessMeta) => void | Promise<void>;
onError?: (IAssertionErrorMeta) => void | Error | Promise<void | Error>;
plugins?: ChaiPlugin[];
}

0 comments on commit 6a2ef52

Please sign in to comment.