Tests: Adds expects for observables (#28929)

* Tests: Adds expects for observables

* Refactor: renames matcher

* Chore: changed jest version and removed as dev dependency

* Refactor: Changes after PR review

* wip

* Chore: revert

* Chore: Adds jest-matcher-utils

* Chore: fixed merge error

* Tests: Removed inline snapshots as they are env dependent

* Tests: missed a snapshot

* Refactor: Removed type file after PR comments
This commit is contained in:
Hugo Häggmark
2020-11-18 15:18:55 +01:00
committed by GitHub
parent 112a755e18
commit 4b711372c5
30 changed files with 1889 additions and 1607 deletions

View File

@ -1,7 +1,7 @@
import { of } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';
import { FetchResponse } from '@grafana/runtime';
import { dateTime, observableTester, toUtc } from '@grafana/data';
import { dateTime, toUtc } from '@grafana/data';
import { PostgresDatasource } from '../datasource';
import { backendSrv } from 'app/core/services/backend_srv'; // will use the version in __mocks__
@ -207,7 +207,7 @@ describe('PostgreSQLDatasource', () => {
});
describe('When performing a query with hidden target', () => {
it('should return empty result and backendSrv.fetch should not be called', done => {
it('should return empty result and backendSrv.fetch should not be called', async () => {
const options = {
range: {
from: dateTime(1432288354),
@ -227,15 +227,9 @@ describe('PostgreSQLDatasource', () => {
const { ds } = setupTestContext({});
observableTester().subscribeAndExpectOnNextAndComplete({
observable: ds.query(options),
expectOnNext: value => {
expect(value).toEqual({ data: [] });
},
expectOnComplete: () => {
expect(fetchMock).not.toHaveBeenCalled();
},
done,
await expect(ds.query(options)).toEmitValuesWith(received => {
expect(received[0]).toEqual({ data: [] });
expect(fetchMock).not.toHaveBeenCalled();
});
});
});