@@ -203,21 +203,18 @@ describe('NodeRequestHandler', () => {
203203 scope . done ( ) ;
204204 } ) ;
205205
206- describe ( 'content-length header ' , ( ) => {
206+ describe ( 'multi-byte unicode data ' , ( ) => {
207207 let server : http . Server ;
208208 let port : number ;
209- let receivedContentLength : string | undefined ;
210- let receivedBodyByteLength : number ;
209+ let receivedBody : string ;
211210
212211 beforeAll ( async ( ) => {
213212 nock . enableNetConnect ( 'localhost' ) ;
214213 server = http . createServer ( ( req , res ) => {
215- receivedContentLength = req . headers [ 'content-length' ] ;
216-
217214 const chunks : Buffer [ ] = [ ] ;
218215 req . on ( 'data' , ( chunk : Buffer ) => chunks . push ( chunk ) ) ;
219216 req . on ( 'end' , ( ) => {
220- receivedBodyByteLength = Buffer . concat ( chunks ) . length ;
217+ receivedBody = Buffer . concat ( chunks ) . toString ( 'utf8' ) ;
221218 res . writeHead ( 200 , { 'content-type' : 'application/json' } ) ;
222219 res . end ( JSON . stringify ( { ok : true } ) ) ;
223220 } ) ;
@@ -236,7 +233,7 @@ describe('NodeRequestHandler', () => {
236233 nock . disableNetConnect ( ) ;
237234 } ) ;
238235
239- it ( 'should set correct content-length for ASCII-only data' , async ( ) => {
236+ it ( 'should correctly transmit ASCII data' , async ( ) => {
240237 const data = '{"key":"value"}' ;
241238
242239 const { responsePromise } = nodeRequestHandler . makeRequest (
@@ -247,12 +244,10 @@ describe('NodeRequestHandler', () => {
247244 ) ;
248245 await responsePromise ;
249246
250- const expectedByteLength = Buffer . byteLength ( data , 'utf8' ) ;
251- expect ( Number ( receivedContentLength ) ) . toBe ( expectedByteLength ) ;
252- expect ( Number ( receivedContentLength ) ) . toBe ( receivedBodyByteLength ) ;
247+ expect ( receivedBody ) . toBe ( data ) ;
253248 } ) ;
254249
255- it ( 'should set correct content-length for multi-byte UTF-8 data (emoji) ' , async ( ) => {
250+ it ( 'should correctly transmit emoji data' , async ( ) => {
256251 const data = JSON . stringify ( { message : '🚀 launch' } ) ;
257252
258253 const { responsePromise } = nodeRequestHandler . makeRequest (
@@ -263,13 +258,10 @@ describe('NodeRequestHandler', () => {
263258 ) ;
264259 await responsePromise ;
265260
266- const expectedByteLength = Buffer . byteLength ( data , 'utf8' ) ;
267- expect ( data . length ) . not . toBe ( expectedByteLength ) ;
268- expect ( Number ( receivedContentLength ) ) . toBe ( expectedByteLength ) ;
269- expect ( Number ( receivedContentLength ) ) . toBe ( receivedBodyByteLength ) ;
261+ expect ( receivedBody ) . toBe ( data ) ;
270262 } ) ;
271263
272- it ( 'should set correct content-length for multi-byte UTF-8 data (CJK characters) ' , async ( ) => {
264+ it ( 'should correctly transmit CJK character data' , async ( ) => {
273265 const data = JSON . stringify ( { greeting : '你好世界' } ) ;
274266
275267 const { responsePromise } = nodeRequestHandler . makeRequest (
@@ -280,10 +272,7 @@ describe('NodeRequestHandler', () => {
280272 ) ;
281273 await responsePromise ;
282274
283- const expectedByteLength = Buffer . byteLength ( data , 'utf8' ) ;
284- expect ( data . length ) . not . toBe ( expectedByteLength ) ;
285- expect ( Number ( receivedContentLength ) ) . toBe ( expectedByteLength ) ;
286- expect ( Number ( receivedContentLength ) ) . toBe ( receivedBodyByteLength ) ;
275+ expect ( receivedBody ) . toBe ( data ) ;
287276 } ) ;
288277 } ) ;
289278
0 commit comments