Skip to content

Commit

Permalink
fix: await for rejections in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdriSolid authored Jan 29, 2021
1 parent 64fe1a4 commit b4520dc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 42 deletions.
24 changes: 10 additions & 14 deletions src/tests/widgets/models/CategoryModel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ import { LayerTypes } from 'src/widgets/LayerTypes';
import { POINTS } from '../data-mocks/pointsForCategories';

describe('getCategories', () => {
test('should thrown an error due to invalid data type', () => {
try {
getCategories({ data: [] });
} catch (err) {
expect(err).toBe('Array is not a valid type to get categories');
}
test('should throw an error due to invalid data type', async () => {
await expect(getCategories({ data: [] })).rejects.toThrow(
'Array is not a valid type to get categories'
);
});

test('should thrown an error if trying to implement client-side-logic with CartoBQTilerLayer', () => {
try {
getCategories({ type: LayerTypes.BQ, viewportFilter: true });
} catch (err) {
expect(err).toBe(
'Category Widget error: BigQuery layers need "viewportFilter" prop set to true.'
);
}
test('should throw an error if trying to implement client-side-logic with CartoBQTilerLayer', async () => {
await expect(
getCategories({ type: LayerTypes.BQ, viewportFilter: false })
).rejects.toThrow(
'Category Widget error: BigQuery layers need "viewportFilter" prop set to true.'
);
});

describe('buildSqlQueryToGetCategories - simple global operations', () => {
Expand Down
24 changes: 10 additions & 14 deletions src/tests/widgets/models/FormulaModel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ import { LayerTypes } from 'src/widgets/LayerTypes';
import { LINES } from '../data-mocks/linesForFormula';

describe('getFormula', () => {
test('should thrown an error due to invalid data type', () => {
try {
getFormula({ data: [] });
} catch (err) {
expect(err).toBe('Array is not a valid type to get formula');
}
test('should throw an error due to invalid data type', async () => {
await expect(getFormula({ data: [] })).rejects.toThrow(
'Array is not a valid type to get formula'
);
});

test('should thrown an error if trying to implement client-side-logic with CartoBQTilerLayer', () => {
try {
getFormula({ type: LayerTypes.BQ, viewportFilter: true });
} catch (err) {
expect(err).toBe(
'Formula Widget error: BigQuery layers need "viewportFilter" prop set to true.'
);
}
test('should throw an error if trying to implement client-side-logic with CartoBQTilerLayer', async () => {
await expect(
getFormula({ type: LayerTypes.BQ, viewportFilter: false })
).rejects.toThrow(
'Formula Widget error: BigQuery layers need "viewportFilter" prop set to true.'
);
});

describe('buildSqlQueryToGetFormula - simple global operations', () => {
Expand Down
24 changes: 10 additions & 14 deletions src/tests/widgets/models/HistogramModel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,18 @@ import { LayerTypes } from 'src/widgets/LayerTypes';
import { POLYGONS } from '../data-mocks/polygonsForHistogram';

describe('getHistogram', () => {
test('should thrown an error due to invalid data type', () => {
try {
getHistogram({ data: [] });
} catch (err) {
expect(err).toBe('Array is not a valid type to get histogram');
}
test('should throw an error due to invalid data type', async () => {
await expect(getHistogram({ data: [] })).rejects.toThrow(
'Array is not a valid type to get histogram'
);
});

test('should thrown an error if trying to implement client-side-logic with CartoBQTilerLayer', () => {
try {
getHistogram({ type: LayerTypes.BQ, viewportFilter: true });
} catch (err) {
expect(err).toBe(
'Category Widget error: BigQuery layers need "viewportFilter" prop set to true.'
);
}
test('should throw an error if trying to implement client-side-logic with CartoBQTilerLayer', async () => {
await expect(
getHistogram({ type: LayerTypes.BQ, viewportFilter: false })
).rejects.toThrow(
'Histogram Widget error: BigQuery layer needs "viewportFilter" prop set to true.'
);
});

describe('buildSqlQueryToGetHistogram - simple global operations', () => {
Expand Down

0 comments on commit b4520dc

Please sign in to comment.