@@ -753,6 +753,44 @@ describe('knex', () => {
753
753
expect ( errorArgs . queryContext ) . to . equal ( context ) ;
754
754
} ) ;
755
755
756
+ it ( 'should show compiled sql on error message when compileSqlOnError is true' , async function ( ) {
757
+ const spy = sinon . spy ( ) ;
758
+ const knex = Knex ( { ...sqliteConfig , compileSqlOnError : true } )
759
+ . from ( 'test' )
760
+ . on ( 'query-error' , spy ) ;
761
+
762
+ try {
763
+ await knex . insert ( { foo : 'bar' } ) ;
764
+ // eslint-disable-next-line no-empty
765
+ } catch ( _e ) { }
766
+
767
+ expect ( spy ) . to . be . calledOnce ;
768
+ const [ [ error ] ] = spy . args ;
769
+ expect ( error ) . to . be . instanceOf ( Error ) ;
770
+ expect ( error . message ) . to . equal (
771
+ "insert into `test` (`foo`) values ('bar') - SQLITE_ERROR: no such table: test"
772
+ ) ;
773
+ } ) ;
774
+
775
+ it ( 'should show parameterized sql on error message when compileSqlOnError is false' , async function ( ) {
776
+ const spy = sinon . spy ( ) ;
777
+ const knex = Knex ( { ...sqliteConfig , compileSqlOnError : false } )
778
+ . from ( 'test' )
779
+ . on ( 'query-error' , spy ) ;
780
+
781
+ try {
782
+ await knex . insert ( { foo : 'bar' } ) ;
783
+ // eslint-disable-next-line no-empty
784
+ } catch ( _e ) { }
785
+
786
+ expect ( spy ) . to . be . calledOnce ;
787
+ const [ [ error ] ] = spy . args ;
788
+ expect ( error ) . to . be . instanceOf ( Error ) ;
789
+ expect ( error . message ) . to . equal (
790
+ 'insert into `test` (`foo`) values (?) - SQLITE_ERROR: no such table: test'
791
+ ) ;
792
+ } ) ;
793
+
756
794
// TODO: Consider moving these somewhere that tests the
757
795
// QueryBuilder interface more directly.
758
796
context ( 'qb = knex.select(1)' , function ( ) {
0 commit comments