Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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([]);
});
});
});
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', () => {