Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions packages/case-core/src/core/executeExample/triggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import type { InvokingScaffold, Trigger } from './types';
import { Assertable } from '../../entities/types';
import { CaseFailedAssertionError } from '../../entities';

const advice = (context: MatchContext) =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's call this missingTriggerAdvice, as it's defined quite a long way from where it's used.

context['_case:currentRun:context:adviceOverrides']?.[
'MISSING_TRIGGER_FUNCTION'
] ?? `Please check that you have configured the appropriate trigger function`;

const invokeTrigger = <T extends AnyMockDescriptorType, R>(
trigger: Trigger<T, R>,
testResponse: (data: R, config: Assertable<T>['config']) => unknown,
Expand Down Expand Up @@ -213,7 +218,7 @@ export const findAndCallTrigger = <T extends AnyMockDescriptorType, R>(
`No trigger for request '${names.requestName}' provided`,
);
throw new CaseConfigurationError(
`No trigger provided for request:\n ${names.requestName}`,
`No trigger provided for request:\n ${names.requestName}\n\n${advice(context)}`,
context,
'MISSING_TRIGGER_FUNCTION',
);
Expand Down Expand Up @@ -251,22 +256,20 @@ export const findAndCallTrigger = <T extends AnyMockDescriptorType, R>(
names.responseName
}\n However, tests for that response name do exist in the following configurations:\n${endsWith
.map((s) => ` ${s.split('::')[0]}`)
.join(
'\n',
)}\n\nPlease check that you have configured the appropriate trigger function\n`,
.join('\n')}\n\n${advice(context)}\n`,
context,
'MISSING_TRIGGER_FUNCTION',
);
}

throw new CaseConfigurationError(
`Missing a trigger for:\n ${names.requestName}\n this should be paired with a test for:\n ${names.responseName}`,
`Missing a trigger for:\n ${names.requestName}\n this should be paired with a test for:\n ${names.responseName}\n\n${advice(context)}`,
context,
'MISSING_TRIGGER_FUNCTION',
);
}
throw new CaseConfigurationError(
`No trigger or trigger map provided for:\n ${names.requestName}\n You must set a trigger or a trigger map`,
`No trigger or trigger map provided for:\n ${names.requestName}\n You must set a trigger or a trigger map\n\n${advice(context)}`,
context,
'MISSING_TRIGGER_FUNCTION',
);
Expand Down
Loading