@@ -3,6 +3,7 @@ import { describe, it } from 'mocha';
33
44import { dedent } from '../../__testUtils__/dedent.js' ;
55import { expectToThrowJSON } from '../../__testUtils__/expectJSON.js' ;
6+ import { expectToThrow } from '../../__testUtils__/expectToThrow.js' ;
67
78import { inspect } from '../../jsutils/inspect.js' ;
89
@@ -173,12 +174,9 @@ describe('Lexer', () => {
173174 } ) ;
174175
175176 it ( 'errors respect whitespace' , ( ) => {
176- let caughtError ;
177- try {
178- lexOne ( [ '' , '' , ' ~' , '' ] . join ( '\n' ) ) ;
179- } catch ( error ) {
180- caughtError = error ;
181- }
177+ const caughtError = expectToThrow ( ( ) =>
178+ lexOne ( [ '' , '' , ' ~' , '' ] . join ( '\n' ) ) ,
179+ ) ;
182180 expect ( String ( caughtError ) ) . to . equal ( dedent `
183181 Syntax Error: Unexpected character: "~".
184182
@@ -191,14 +189,11 @@ describe('Lexer', () => {
191189 } ) ;
192190
193191 it ( 'updates line numbers in error for file context' , ( ) => {
194- let caughtError ;
195- try {
192+ const caughtError = expectToThrow ( ( ) => {
196193 const str = [ '' , '' , ' ~' , '' ] . join ( '\n' ) ;
197194 const source = new Source ( str , 'foo.js' , { line : 11 , column : 12 } ) ;
198195 new Lexer ( source ) . advance ( ) ;
199- } catch ( error ) {
200- caughtError = error ;
201- }
196+ } ) ;
202197 expect ( String ( caughtError ) ) . to . equal ( dedent `
203198 Syntax Error: Unexpected character: "~".
204199
@@ -211,13 +206,10 @@ describe('Lexer', () => {
211206 } ) ;
212207
213208 it ( 'updates column numbers in error for file context' , ( ) => {
214- let caughtError ;
215- try {
209+ const caughtError = expectToThrow ( ( ) => {
216210 const source = new Source ( '~' , 'foo.js' , { line : 1 , column : 5 } ) ;
217211 new Lexer ( source ) . advance ( ) ;
218- } catch ( error ) {
219- caughtError = error ;
220- }
212+ } ) ;
221213 expect ( String ( caughtError ) ) . to . equal ( dedent `
222214 Syntax Error: Unexpected character: "~".
223215
0 commit comments