Commit 962340bc by Tobias Skarhed

Create new instance in beforeEach

parent a37a0c7b
...@@ -5,15 +5,17 @@ import { MysqlDatasource } from '../datasource'; ...@@ -5,15 +5,17 @@ import { MysqlDatasource } from '../datasource';
import { CustomVariable } from 'app/features/templating/custom_variable'; import { CustomVariable } from 'app/features/templating/custom_variable';
describe('MySQLDatasource', function() { describe('MySQLDatasource', function() {
let instanceSettings = { name: 'mysql' }; let instanceSettings = { name: 'mysql' };
let backendSrv = {}; let backendSrv = {};
let templateSrv = new TemplateSrvStub(); let templateSrv = new TemplateSrvStub();
let ctx = <any>{ let ctx = <any>{
ds: new MysqlDatasource(instanceSettings, backendSrv, {}, templateSrv), backendSrv,
backendSrv
}; };
beforeEach(() => {
ctx.ds = new MysqlDatasource(instanceSettings, backendSrv, {}, templateSrv);
});
describe('When performing annotationQuery', function() { describe('When performing annotationQuery', function() {
let results; let results;
...@@ -49,7 +51,7 @@ describe('MySQLDatasource', function() { ...@@ -49,7 +51,7 @@ describe('MySQLDatasource', function() {
}; };
beforeEach(function() { beforeEach(function() {
ctx.backendSrv.datasourceRequest = jest.fn((options) => { ctx.backendSrv.datasourceRequest = jest.fn(options => {
return Promise.resolve({ data: response, status: 200 }); return Promise.resolve({ data: response, status: 200 });
}); });
ctx.ds.annotationQuery(options).then(function(data) { ctx.ds.annotationQuery(options).then(function(data) {
...@@ -92,7 +94,7 @@ describe('MySQLDatasource', function() { ...@@ -92,7 +94,7 @@ describe('MySQLDatasource', function() {
}; };
beforeEach(function() { beforeEach(function() {
ctx.backendSrv.datasourceRequest = jest.fn((options) => { ctx.backendSrv.datasourceRequest = jest.fn(options => {
return Promise.resolve({ data: response, status: 200 }); return Promise.resolve({ data: response, status: 200 });
}); });
ctx.ds.metricFindQuery(query).then(function(data) { ctx.ds.metricFindQuery(query).then(function(data) {
...@@ -128,7 +130,7 @@ describe('MySQLDatasource', function() { ...@@ -128,7 +130,7 @@ describe('MySQLDatasource', function() {
}; };
beforeEach(function() { beforeEach(function() {
ctx.backendSrv.datasourceRequest = jest.fn((options) => { ctx.backendSrv.datasourceRequest = jest.fn(options => {
return Promise.resolve({ data: response, status: 200 }); return Promise.resolve({ data: response, status: 200 });
}); });
ctx.ds.metricFindQuery(query).then(function(data) { ctx.ds.metricFindQuery(query).then(function(data) {
...@@ -166,7 +168,7 @@ describe('MySQLDatasource', function() { ...@@ -166,7 +168,7 @@ describe('MySQLDatasource', function() {
}; };
beforeEach(function() { beforeEach(function() {
ctx.backendSrv.datasourceRequest = jest.fn((options) => { ctx.backendSrv.datasourceRequest = jest.fn(options => {
return Promise.resolve({ data: response, status: 200 }); return Promise.resolve({ data: response, status: 200 });
}); });
ctx.ds.metricFindQuery(query).then(function(data) { ctx.ds.metricFindQuery(query).then(function(data) {
......
...@@ -9,10 +9,13 @@ describe('PostgreSQLDatasource', function() { ...@@ -9,10 +9,13 @@ describe('PostgreSQLDatasource', function() {
let backendSrv = {}; let backendSrv = {};
let templateSrv = new TemplateSrvStub(); let templateSrv = new TemplateSrvStub();
let ctx = <any>{ let ctx = <any>{
ds: new PostgresDatasource(instanceSettings, backendSrv, {}, templateSrv), backendSrv,
backendSrv
}; };
beforeEach(() => {
ctx.ds = new PostgresDatasource(instanceSettings, backendSrv, {}, templateSrv);
});
describe('When performing annotationQuery', function() { describe('When performing annotationQuery', function() {
let results; let results;
...@@ -48,7 +51,7 @@ describe('PostgreSQLDatasource', function() { ...@@ -48,7 +51,7 @@ describe('PostgreSQLDatasource', function() {
}; };
beforeEach(function() { beforeEach(function() {
ctx.backendSrv.datasourceRequest = jest.fn((options) => { ctx.backendSrv.datasourceRequest = jest.fn(options => {
return Promise.resolve({ data: response, status: 200 }); return Promise.resolve({ data: response, status: 200 });
}); });
ctx.ds.annotationQuery(options).then(function(data) { ctx.ds.annotationQuery(options).then(function(data) {
...@@ -91,7 +94,7 @@ describe('PostgreSQLDatasource', function() { ...@@ -91,7 +94,7 @@ describe('PostgreSQLDatasource', function() {
}; };
beforeEach(function() { beforeEach(function() {
ctx.backendSrv.datasourceRequest = jest.fn((options) => { ctx.backendSrv.datasourceRequest = jest.fn(options => {
return Promise.resolve({ data: response, status: 200 }); return Promise.resolve({ data: response, status: 200 });
}); });
ctx.ds.metricFindQuery(query).then(function(data) { ctx.ds.metricFindQuery(query).then(function(data) {
...@@ -127,7 +130,7 @@ describe('PostgreSQLDatasource', function() { ...@@ -127,7 +130,7 @@ describe('PostgreSQLDatasource', function() {
}; };
beforeEach(function() { beforeEach(function() {
ctx.backendSrv.datasourceRequest = jest.fn((options) => { ctx.backendSrv.datasourceRequest = jest.fn(options => {
return Promise.resolve({ data: response, status: 200 }); return Promise.resolve({ data: response, status: 200 });
}); });
ctx.ds.metricFindQuery(query).then(function(data) { ctx.ds.metricFindQuery(query).then(function(data) {
...@@ -165,7 +168,7 @@ describe('PostgreSQLDatasource', function() { ...@@ -165,7 +168,7 @@ describe('PostgreSQLDatasource', function() {
}; };
beforeEach(() => { beforeEach(() => {
ctx.backendSrv.datasourceRequest = jest.fn((options) => { ctx.backendSrv.datasourceRequest = jest.fn(options => {
return Promise.resolve({ data: response, status: 200 }); return Promise.resolve({ data: response, status: 200 });
}); });
ctx.ds.metricFindQuery(query).then(function(data) { ctx.ds.metricFindQuery(query).then(function(data) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment