From b4520dc407dd7ffb1b2d48c0065da9d288814ab7 Mon Sep 17 00:00:00 2001 From: AdriSolid Date: Fri, 29 Jan 2021 17:10:48 +0100 Subject: [PATCH] fix: await for rejections in tests --- .../widgets/models/CategoryModel.test.js | 24 ++++++++----------- src/tests/widgets/models/FormulaModel.test.js | 24 ++++++++----------- .../widgets/models/HistogramModel.test.js | 24 ++++++++----------- 3 files changed, 30 insertions(+), 42 deletions(-) diff --git a/src/tests/widgets/models/CategoryModel.test.js b/src/tests/widgets/models/CategoryModel.test.js index 78abe183b..d02aa71ef 100644 --- a/src/tests/widgets/models/CategoryModel.test.js +++ b/src/tests/widgets/models/CategoryModel.test.js @@ -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', () => { diff --git a/src/tests/widgets/models/FormulaModel.test.js b/src/tests/widgets/models/FormulaModel.test.js index 6e6685589..b292af71c 100644 --- a/src/tests/widgets/models/FormulaModel.test.js +++ b/src/tests/widgets/models/FormulaModel.test.js @@ -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', () => { diff --git a/src/tests/widgets/models/HistogramModel.test.js b/src/tests/widgets/models/HistogramModel.test.js index d4ebe265b..19bd7405d 100644 --- a/src/tests/widgets/models/HistogramModel.test.js +++ b/src/tests/widgets/models/HistogramModel.test.js @@ -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', () => {