11'use strict'
2+
3+ import { createRequire } from 'module'
4+ import chaiAsPromised from 'chai-as-promised'
5+
26/* globals describe it */
37
8+ const totalObjectsForInsert = 10
9+ const test1BatchSize = 1
10+ const test2BatchSize = 10
11+ const require = createRequire ( import . meta. url )
412const { TestEnv } = require ( './env/test-env' )
513const env = new TestEnv ( )
614const chai = require ( 'chai' )
15+ chai . use ( chaiAsPromised )
716const expect = chai . expect
817const assert = chai . assert
918
10- const totalObjectsForInsert = 10
11- const test1BatchSize = 1
12- const test2BatchSize = 10
13-
1419describe ( 'bulk' , function ( ) {
1520 this . timeout ( 100000 )
1621
@@ -857,6 +862,11 @@ describe('bulk', function () {
857862 assert ( table !== null )
858863 } )
859864
865+ async function doesThrow ( sql , message , connection ) {
866+ const proxy = connection || env . theConnection
867+ await expect ( proxy . promises . query ( sql ) ) . to . be . rejectedWith ( message )
868+ }
869+
860870 it ( 'bulk insert condition failure' , async function handler ( ) {
861871 const createTableSql = 'CREATE TABLE Persons (Name varchar(255) NOT NULL)'
862872 await env . theConnection . promises . query ( env . dropTableSql ( 'Persons' ) )
@@ -867,9 +877,9 @@ describe('bulk', function () {
867877 const nullJohn = 'INSERT INTO [Persons] ([Name]) OUTPUT INSERTED.* VALUES (null), (N\'John\')'
868878 const error = 'Cannot insert the value NULL into column'
869879
870- await env . doesThrow ( johnNullSql , error )
871- await env . doesThrow ( nullSql , error )
872- await env . doesThrow ( nullJohn , error )
880+ await doesThrow ( johnNullSql , error )
881+ await doesThrow ( nullSql , error )
882+ await doesThrow ( nullJohn , error )
873883 } )
874884
875885 it ( 'non null varchar write empty string' , async function handler ( ) {
0 commit comments