Testing Request Content Length Handling in Koa.js
This test suite examines the content length handling functionality in Koa’s request context. It verifies the proper parsing and retrieval of the Content-Length header value, ensuring accurate request size determination in the Koa framework.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
koajs/koa
__tests__/request/length.test.js
'use strict'
const { describe, it } = require('node:test')
const request = require('../../test-helpers/context').request
const assert = require('assert')
describe('ctx.length', () => {
it('should return length in content-length', () => {
const req = request()
req.header['content-length'] = '10'
assert.strictEqual(req.length, 10)
})
it('should return undefined with no content-length present', () => {
const req = request()
assert.strictEqual(req.length, undefined)
})
})