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.
npm install pgtestNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: set an expected SQL query with return data, run it through a mocked client, and verify expectations.
Consider using a more modern PostgreSQL mock library like pg-mem, mock-knex, or sinon for promise-based testing.
Call pgtest.reset() before each test case, e.g., in a beforeEach hook.
Register expectations in the same order queries are called in your code.
Access query results via result.rows, not result directly.
Use var pgtest = require('pgtest');Run npm install pgtest --save-dev
Ensure you are using the client returned from pgtest.connect().
No dependency data recorded yet.