Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gajus/slonik
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v35.0.1
Choose a base ref
...
head repository: gajus/slonik
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v35.0.2
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Sep 27, 2023

  1. Copy the full SHA
    5f05094 View commit details
Showing with 18 additions and 4 deletions.
  1. +4 −4 src/factories/createMockPool.ts
  2. +14 −0 test/slonik/factories/createMockPool.ts
8 changes: 4 additions & 4 deletions src/factories/createMockPool.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import {
} from '../types';
import { createUid } from '../utilities/createUid';
import { createClientConfiguration } from './createClientConfiguration';
import { type Pool as PgPool, type PoolClient as PgClientPool } from 'pg';

export const createMockPool = (
overrides: MockPoolOverrides,
@@ -30,13 +31,12 @@ export const createMockPool = (
on: () => {},
query: overrides.query,
release: () => {},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
} as unknown as PgClientPool;

return connection;
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any;
end: async () => {},
} as unknown as PgPool;

poolStateMap.set(pool, {
ended: false,
14 changes: 14 additions & 0 deletions test/slonik/factories/createMockPool.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,20 @@ import { createMockQueryResult } from '../../../src/factories/createMockQueryRes
import test from 'ava';
import * as sinon from 'sinon';

test('ends pool', async (t) => {
const pool = createMockPool({
query: async () => {
return createMockQueryResult([]);
},
});

t.false(pool.getPoolState().ended);

await pool.end();

t.true(pool.getPoolState().ended);
});

test('executes a mock query (pool.query)', async (t) => {
t.plan(4);