How to use the pg.Pool.prototype function in pg

To help you get started, we’ve selected a few pg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jmcdo29 / zeldaPlay / src / server / app / db / db.service.spec.ts View on Github external
it('should return an empty array because of a bad query', () => {
      const querySpy = (Pool.prototype.query as any).mockImplementationOnce(
        () => Promise.reject(new Error('Error'))
      );
      service.query('This is a bad query', []).subscribe((qResult) => {
        expect(querySpy).toBeCalledTimes(2);
        expect(querySpy).toBeCalledWith('This is a bad query', []);
        expect(qResult).toEqual([]);
      });
    });
  });
github jmcdo29 / zeldaPlay / src / server / app / db / db.service.spec.ts View on Github external
import { Test, TestingModule } from '@nestjs/testing';
import { Pool } from 'pg';

import { MyLogger } from '../logger/logger.service';
import { DbService } from './db.service';
Pool.prototype.connect = jest.fn();
jest.mock('pg');

describe('DbService', () => {
  let service: DbService;

  beforeAll(async () => {
    const module: TestingModule = await Test.createTestingModule({
      providers: [DbService, MyLogger]
    }).compile();
    module.init();
    service = module.get(DbService);
  });
  it('should be defined', () => {
    expect(service).toBeDefined();
  });
  describe('#query', () => {