@@ -19,9 +19,8 @@ describe('errors', () => {
1919 describe ( 'handle' , ( ) => {
2020 it ( 'returns the result when the function succeeds' , async ( ) => {
2121 const mockFn = jest . fn ( ) . mockResolvedValue ( 'success' ) ;
22- const scope = 'test-scope' ;
2322
24- const result = await withCatchAndThrowSnapError ( scope , mockFn ) ;
23+ const result = await withCatchAndThrowSnapError ( mockFn ) ;
2524
2625 expect ( result ) . toBe ( 'success' ) ;
2726 expect ( mockFn ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -31,9 +30,8 @@ describe('errors', () => {
3130 it ( 'handles and re-throws errors as SnapError' , async ( ) => {
3231 const originalError = new Error ( 'Test error' ) ;
3332 const mockFn = jest . fn ( ) . mockRejectedValue ( originalError ) ;
34- const scope = 'test-scope' ;
3533
36- await expect ( withCatchAndThrowSnapError ( scope , mockFn ) ) . rejects . toThrow (
34+ await expect ( withCatchAndThrowSnapError ( mockFn ) ) . rejects . toThrow (
3735 SnapError ,
3836 ) ;
3937
@@ -44,17 +42,16 @@ describe('errors', () => {
4442 it ( 'logs errors with the correct scope and error details' , async ( ) => {
4543 const originalError = new Error ( 'Test error' ) ;
4644 const mockFn = jest . fn ( ) . mockRejectedValue ( originalError ) ;
47- const scope = 'test-scope' ;
4845
4946 try {
50- await withCatchAndThrowSnapError ( scope , mockFn ) ;
47+ await withCatchAndThrowSnapError ( mockFn ) ;
5148 } catch ( error ) {
5249 // Expected to throw
5350 }
5451
5552 expect ( mockLogger . error ) . toHaveBeenCalledWith (
5653 { error : expect . any ( SnapError ) } ,
57- expect . stringContaining ( `[${ scope } ] Error occurred: ` ) ,
54+ expect . stringContaining ( `[SnapError] ` ) ,
5855 ) ;
5956
6057 expect ( mockLogger . error ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -66,9 +63,8 @@ describe('errors', () => {
6663 it ( 'handles non-Error objects and converts them to SnapError' , async ( ) => {
6764 const nonErrorValue = 'string error' ;
6865 const mockFn = jest . fn ( ) . mockRejectedValue ( nonErrorValue ) ;
69- const scope = 'test-scope' ;
7066
71- await expect ( withCatchAndThrowSnapError ( scope , mockFn ) ) . rejects . toThrow (
67+ await expect ( withCatchAndThrowSnapError ( mockFn ) ) . rejects . toThrow (
7268 SnapError ,
7369 ) ;
7470
@@ -80,9 +76,8 @@ describe('errors', () => {
8076
8177 it ( 'handles null and undefined errors' , async ( ) => {
8278 const mockFn = jest . fn ( ) . mockRejectedValue ( null ) ;
83- const scope = 'test-scope' ;
8479
85- await expect ( withCatchAndThrowSnapError ( scope , mockFn ) ) . rejects . toThrow (
80+ await expect ( withCatchAndThrowSnapError ( mockFn ) ) . rejects . toThrow (
8681 SnapError ,
8782 ) ;
8883
@@ -92,11 +87,10 @@ describe('errors', () => {
9287 it ( 'preserves the original error message in the SnapError' , async ( ) => {
9388 const originalError = new Error ( 'Custom error message' ) ;
9489 const mockFn = jest . fn ( ) . mockRejectedValue ( originalError ) ;
95- const scope = 'test-scope' ;
9690
9791 let caughtError : unknown ;
9892 try {
99- await withCatchAndThrowSnapError ( scope , mockFn ) ;
93+ await withCatchAndThrowSnapError ( mockFn ) ;
10094 } catch ( error ) {
10195 caughtError = error ;
10296 }
@@ -117,9 +111,8 @@ describe('errors', () => {
117111
118112 for ( const testCase of testCases ) {
119113 const mockFn = jest . fn ( ) . mockResolvedValue ( testCase . value ) ;
120- const scope = 'test-scope' ;
121114
122- const result = await withCatchAndThrowSnapError ( scope , mockFn ) ;
115+ const result = await withCatchAndThrowSnapError ( mockFn ) ;
123116
124117 expect ( result ) . toBe ( testCase . value ) ;
125118 expect ( mockLogger . error ) . not . toHaveBeenCalled ( ) ;
@@ -136,9 +129,8 @@ describe('errors', () => {
136129
137130 for ( const errorType of errorTypes ) {
138131 const mockFn = jest . fn ( ) . mockRejectedValue ( errorType ) ;
139- const scope = 'test-scope' ;
140132
141- await expect ( withCatchAndThrowSnapError ( scope , mockFn ) ) . rejects . toThrow (
133+ await expect ( withCatchAndThrowSnapError ( mockFn ) ) . rejects . toThrow (
142134 SnapError ,
143135 ) ;
144136 }
@@ -159,10 +151,9 @@ describe('errors', () => {
159151 const originalError = new Error ( 'Test error' ) ;
160152 originalError . stack = 'Error: Test error\n at test.js:1:1' ;
161153 const mockFn = jest . fn ( ) . mockRejectedValue ( originalError ) ;
162- const scope = 'test-scope' ;
163154
164155 try {
165- await withCatchAndThrowSnapError ( scope , mockFn ) ;
156+ await withCatchAndThrowSnapError ( mockFn ) ;
166157 } catch ( error ) {
167158 // Expected to throw
168159 }
@@ -176,9 +167,8 @@ describe('errors', () => {
176167 it ( 'handles functions that throw promises' , async ( ) => {
177168 const rejectedPromise = Promise . reject ( new Error ( 'Promise error' ) ) ;
178169 const mockFn = jest . fn ( ) . mockImplementation ( async ( ) => rejectedPromise ) ;
179- const scope = 'test-scope' ;
180170
181- await expect ( withCatchAndThrowSnapError ( scope , mockFn ) ) . rejects . toThrow (
171+ await expect ( withCatchAndThrowSnapError ( mockFn ) ) . rejects . toThrow (
182172 SnapError ,
183173 ) ;
184174
0 commit comments