@@ -12,24 +12,37 @@ type ScenarioFn<T> = (
1212 instance : AutoAPIMockInstance < T > ,
1313) => AutoAPIMockInstance < T > ;
1414
15- export interface UseScenarioOptions {
15+ export interface ActivateScenarioOptions {
1616 /** If true, silently falls back to default when scenario doesn't exist. Default: false (throws) */
1717 fallbackToDefault ?: boolean ;
1818}
1919
2020export interface AutoAPIMockInstance < T > {
21+ /** Internal MSW handler - don't call directly */
2122 generatedHandler : HttpResponseResolver ;
23+
24+ /** Override response data with type safety. Preferred for simple data changes. */
2225 override : ( fn : OverrideFn < T > ) => AutoAPIMockInstance < T > ;
26+
27+ /** Override the full handler. Use for errors, network failures, or invalid data. */
2328 overrideHandler : ( fn : OverrideHandlerFn < T > ) => AutoAPIMockInstance < T > ;
29+
30+ /** Define a reusable named scenario for this mock. */
2431 scenario : (
2532 name : MockScenarioName ,
2633 fn : ScenarioFn < T > ,
2734 ) => AutoAPIMockInstance < T > ;
28- useScenario : (
35+
36+ /** Activate a named scenario for the current test. */
37+ activateScenario : (
2938 name : MockScenarioName ,
30- options ?: UseScenarioOptions ,
39+ options ?: ActivateScenarioOptions ,
3140 ) => AutoAPIMockInstance < T > ;
41+
42+ /** Reset to default behavior. Called automatically before each test. */
3243 reset : ( ) => AutoAPIMockInstance < T > ;
44+
45+ /** The default fixture data. */
3346 defaultValue : T ;
3447}
3548
@@ -83,7 +96,10 @@ export function AutoAPIMock<T>(defaultValue: T): AutoAPIMockInstance<T> {
8396 return instance ;
8497 } ,
8598
86- useScenario ( name : MockScenarioName , options ?: UseScenarioOptions ) {
99+ activateScenario (
100+ name : MockScenarioName ,
101+ options ?: ActivateScenarioOptions ,
102+ ) {
87103 const scenarioFn = scenarios . get ( name ) ;
88104 if ( ! scenarioFn ) {
89105 if ( options ?. fallbackToDefault ) {
@@ -119,7 +135,6 @@ export function resetAllAutoAPIMocks(): void {
119135 */
120136export function activateMockScenario ( name : MockScenarioName ) : void {
121137 for ( const instance of registry ) {
122- // biome-ignore lint/correctness/useHookAtTopLevel: useScenario is not a React hook
123- instance . useScenario ( name , { fallbackToDefault : true } ) ;
138+ instance . activateScenario ( name , { fallbackToDefault : true } ) ;
124139 }
125140}
0 commit comments