@@ -250,8 +250,8 @@ test.describe('pre-request features tests', () => {
250
250
251
251
// enter script
252
252
await page . getByRole ( 'tab' , { name : 'Scripts' } ) . click ( ) ;
253
- const preRequestScriptEditor = page . getByTestId ( 'CodeEditor' ) . getByRole ( 'textbox' ) ;
254
- await preRequestScriptEditor . fill ( `
253
+ const editor = page . getByTestId ( 'CodeEditor' ) . getByRole ( 'textbox' ) ;
254
+ await editor . fill ( `
255
255
const rawReq = {
256
256
url: 'http://127.0.0.1:4010/echo',
257
257
method: 'POST',
@@ -634,56 +634,40 @@ test.describe('unhappy paths', () => {
634
634
await page . getByLabel ( 'Pre-request Scripts' ) . click ( ) ;
635
635
} ) ;
636
636
637
- const testCases = [
638
- {
639
- name : 'custom error is returned' ,
640
- preReqScript : `
641
- throw Error('my custom error');
642
- ` ,
643
- context : {
644
- insomnia : { } ,
645
- } ,
646
- expectedResult : {
647
- message : 'my custom error' ,
648
- } ,
649
- } ,
650
- {
651
- name : 'syntax error' ,
652
- preReqScript : `
653
- insomnia.INVALID_FIELD.set('', '')
654
- ` ,
655
- context : {
656
- insomnia : { } ,
657
- } ,
658
- expectedResult : {
659
- message : "Cannot read properties of undefined (reading 'set')" ,
660
- } ,
661
- } ,
662
- ] ;
637
+ test ( 'custom errors are returned' , async ( { page } ) => {
638
+ await page . getByLabel ( 'Request Collection' ) . getByTestId ( 'echo pre-request script result' ) . press ( 'Enter' ) ;
639
+
640
+ // set request body
641
+ await page . getByRole ( 'tab' , { name : 'Body' } ) . click ( ) ;
642
+ await page . getByRole ( 'button' , { name : 'Body' } ) . click ( ) ;
643
+ await page . getByRole ( 'option' , { name : 'JSON' } ) . click ( ) ;
644
+
645
+ // enter script
646
+ await page . getByRole ( 'tab' , { name : 'Scripts' } ) . click ( ) ;
647
+ const editor = page . getByTestId ( 'CodeEditor' ) . getByRole ( 'textbox' ) ;
648
+ await editor . fill ( `throw Error('my custom error');` ) ;
663
649
664
- for ( const tc of testCases ) {
665
- test ( tc . name , async ( { page } ) => {
666
- const responsePane = page . getByTestId ( 'response-pane' ) ;
650
+ await page . getByRole ( 'tab' , { name : 'Body' } ) . click ( ) ;
667
651
668
- await page . getByLabel ( 'Request Collection' ) . getByTestId ( 'echo pre-request script result' ) . press ( 'Enter' ) ;
652
+ // send
653
+ await page . getByTestId ( 'request-pane' ) . getByRole ( 'button' , { name : 'Send' } ) . click ( ) ;
669
654
670
- // set request body
671
- await page . getByRole ( 'tab' , { name : 'Body' } ) . click ( ) ;
672
- await page . getByRole ( 'button' , { name : 'Body' } ) . click ( ) ;
673
- await page . getByRole ( 'option' , { name : 'JSON' } ) . click ( ) ;
655
+ // verify
656
+ await expect . soft ( page . getByTestId ( 'response-pane' ) ) . toContainText ( 'my custom error' ) ;
674
657
675
- // enter script
676
- await page . getByRole ( 'tab' , { name : 'Scripts' } ) . click ( ) ;
677
- const preRequestScriptEditor = page . getByTestId ( 'CodeEditor' ) . getByRole ( 'textbox ') ;
678
- await preRequestScriptEditor . fill ( tc . preReqScript ) ;
658
+ await page . getByRole ( 'tab' , { name : 'Scripts' } ) . click ( ) ;
659
+ await page . getByTestId ( 'CodeEditor' ) . getByRole ( 'textbox' ) . press ( 'ControlOrMeta+a' ) ;
660
+ await page . keyboard . press ( 'Backspace ') ;
661
+ await editor . fill ( `insomnia.INVALID_FIELD.set('', '')` ) ;
679
662
680
- await page . getByRole ( 'tab' , { name : 'Body' } ) . click ( ) ;
663
+ await page . getByRole ( 'tab' , { name : 'Body' } ) . click ( ) ;
681
664
682
- // send
683
- await page . getByTestId ( 'request-pane' ) . getByRole ( 'button' , { name : 'Send' } ) . click ( ) ;
665
+ // send
666
+ await page . getByTestId ( 'request-pane' ) . getByRole ( 'button' , { name : 'Send' } ) . click ( ) ;
684
667
685
- // verify
686
- await expect . soft ( responsePane ) . toContainText ( tc . expectedResult . message ) ;
687
- } ) ;
688
- }
668
+ // verify
669
+ await expect
670
+ . soft ( page . getByTestId ( 'response-pane' ) )
671
+ . toContainText ( `Cannot read properties of undefined (reading 'set')` ) ;
672
+ } ) ;
689
673
} ) ;
0 commit comments