pgtest is a drop-in replacement for node-postgres (pg) intended for unit testing. It allows you to mock database queries by specifying expected SQL strings or regular expressions, along with custom return data or errors. The current version is 0.2.3, and the library has seen no recent updates (last release appears years ago). It works with callbacks only, relying on rewire or similar tools to inject the mock into modules under test. Key differentiators: simple API, inline expectations without a separate query builder, and built-in verify/check to ensure all expectations were consumed. However, it does not support promises or async/await, and is not actively maintained, making it suitable only for legacy callback-based codebases.
No compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
This package uses CommonJS and does not provide ES module exports. Use require() in Node.js environments.
connect() does not return a Promise; it invokes the callback immediately with a mocked client.
The .returning() data should be an array of rows, not wrapped in {rows: ...}. The library internally adds the rows property.
Demonstrates basic usage: set an expected SQL query with return data, run it through a mocked client, and verify expectations.
Breaking-change detection hasn't run for this library yet.
CVE tracking and dependency tree are planned for a later release.