Testing ETag Header Implementation in koajs/koa
This test suite validates the ETag header functionality in Koa’s response handling. It ensures proper formatting and manipulation of ETag values, which are crucial for HTTP caching mechanisms and content validation.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
koajs/koa
__tests__/response/etag.test.js
'use strict'
const { describe, it } = require('node:test')
const assert = require('assert')
const response = require('../../test-helpers/context').response
describe('res.etag=', () => {
it('should not modify an etag with quotes', () => {
const res = response()
res.etag = '"asdf"'
assert.strictEqual(res.header.etag, '"asdf"')
})
it('should not modify a weak etag', () => {
const res = response()
res.etag = 'W/"asdf"'
assert.strictEqual(res.header.etag, 'W/"asdf"')
})
it('should add quotes around an etag if necessary', () => {
const res = response()
res.etag = 'asdf'
assert.strictEqual(res.header.etag, '"asdf"')
})
})
describe('res.etag', () => {
it('should return etag', () => {
const res = response()
res.etag = '"asdf"'
assert.strictEqual(res.etag, '"asdf"')
})
})