Testing Request Stale Property Implementation in koajs/koa
This test suite validates the stale property functionality in Koa’s request handling, specifically examining the relationship between stale and fresh states in HTTP caching mechanisms. The tests ensure proper behavior of ETag-based cache validation.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
koajs/koa
__tests__/request/stale.test.js
'use strict'
const { describe, it } = require('node:test')
const assert = require('assert')
const context = require('../../test-helpers/context')
describe('req.stale', () => {
it('should be the inverse of req.fresh', () => {
const ctx = context()
ctx.status = 200
ctx.method = 'GET'
ctx.req.headers['if-none-match'] = '"123"'
ctx.set('ETag', '"123"')
assert.strictEqual(ctx.fresh, true)
assert.strictEqual(ctx.stale, false)
})
})