From a31f4965daf8d8fe511b8f8b30c5241543edc91b Mon Sep 17 00:00:00 2001 From: Zach Wegrzyniak Date: Tue, 28 Jan 2025 15:46:22 -0500 Subject: [PATCH] tidy(web): Move test assertions over to jest style (#7766) * Fix #7761 * patch up types for tsconfig.node * patch up types for tsconfig.node once more * buff out one more chai style assertion * continue using chai expect in cypress tests * drop eslint-disable --- web/.eslintrc.json | 1 + web/geo/validate.test.ts | 6 +- web/scripts/generateZonesConfig.test.ts | 8 +- web/src/components/TimeSlider.test.tsx | 4 +- .../charts/bar-breakdown/utils.test.ts | 46 +++--- .../features/charts/futurePriceUtils.test.ts | 34 +++-- web/src/features/charts/graphUtils.test.ts | 46 +++--- .../charts/tooltipCalculations.test.ts | 8 +- .../weather-layers/solar/utils.test.ts | 14 +- .../weather-layers/wind-layer/calc.test.ts | 29 ++-- .../weather-layers/wind-layer/windy.test.ts | 8 +- web/src/hooks/nightTimes.test.ts | 6 +- web/src/translation/translation.test.ts | 4 +- web/src/utils/formatting.test.ts | 138 +++++++++--------- web/src/utils/helpers.test.ts | 50 +++---- web/src/utils/styling.test.ts | 5 +- 16 files changed, 212 insertions(+), 195 deletions(-) diff --git a/web/.eslintrc.json b/web/.eslintrc.json index 2392594f23..7856d89fb6 100644 --- a/web/.eslintrc.json +++ b/web/.eslintrc.json @@ -87,6 +87,7 @@ "devDependencies": [ "cypress.config.ts", "vite.config.ts", + "scripts/**/*.test.ts", "src/testing/setupTests.ts", "src/testing/testUtils.tsx", "src/testing/mocks/**", diff --git a/web/geo/validate.test.ts b/web/geo/validate.test.ts index 9c386c7eba..371314d957 100644 --- a/web/geo/validate.test.ts +++ b/web/geo/validate.test.ts @@ -1,3 +1,5 @@ +import { describe, expect, it } from 'vitest'; + import { GEO_CONFIG } from './generateWorld'; import { WorldFeatureCollection } from './types'; import { zeroOverlaps } from './validate'; @@ -169,7 +171,7 @@ const mockFeatureCollection: WorldFeatureCollection = { describe('zeroOverlaps', () => { it('should not throw if there are no overlaps', () => { // assert that function does not throw error - expect(() => zeroOverlaps(mockFeatureCollection, GEO_CONFIG)).not.to.throw(); + expect(() => zeroOverlaps(mockFeatureCollection, GEO_CONFIG)).not.toThrow(); }); it('should throw on overlaps', () => { @@ -179,7 +181,7 @@ describe('zeroOverlaps', () => { overlappingFeatureCollection.features[1].geometry.coordinates[1][0][0][0] = 11.0754; overlappingFeatureCollection.features[1].geometry.coordinates[1][0][8][0] = 11.0754; // assert that function throws error with specific message - expect(() => zeroOverlaps(overlappingFeatureCollection, GEO_CONFIG)).to.throw( + expect(() => zeroOverlaps(overlappingFeatureCollection, GEO_CONFIG)).toThrow( 'SE-SE3 overlaps with SE-SE4' ); }); diff --git a/web/scripts/generateZonesConfig.test.ts b/web/scripts/generateZonesConfig.test.ts index 78b8183388..f2c4040b5f 100644 --- a/web/scripts/generateZonesConfig.test.ts +++ b/web/scripts/generateZonesConfig.test.ts @@ -1,3 +1,5 @@ +import { describe, expect, it } from 'vitest'; + import { getConfig } from './generateZonesConfig'; describe('generateZonesConfig', () => { @@ -10,10 +12,10 @@ describe('generateZonesConfig', () => { const indexOfContributor = result.contributors.indexOf(contributorName); // Person should be in the list of contributors - expect(result.contributors).to.contain(contributorName); + expect(result.contributors).toContain(contributorName); // Person should be in the list of contributors for the zone - expect(result.zones['DK-DK2'].contributors).to.contain(indexOfContributor); + expect(result.zones['DK-DK2'].contributors).toContain(indexOfContributor); // Person should be in the list of contributors for the aggregated country - expect(result.zones['DK'].contributors).to.contain(indexOfContributor); + expect(result.zones['DK'].contributors).toContain(indexOfContributor); }); }); diff --git a/web/src/components/TimeSlider.test.tsx b/web/src/components/TimeSlider.test.tsx index 82f25a7f1e..f97d9e2bba 100644 --- a/web/src/components/TimeSlider.test.tsx +++ b/web/src/components/TimeSlider.test.tsx @@ -6,8 +6,8 @@ import { COLORS, getThumbIcon, getTrackBackground } from './TimeSlider'; describe('getTrackBackground', () => { it('returns the day color when no sets are provided', () => { - expect(getTrackBackground(false, 10)).to.eq(COLORS.LIGHT_DAY); - expect(getTrackBackground(true, 10)).to.eq(COLORS.DARK_DAY); + expect(getTrackBackground(false, 10)).toEqual(COLORS.LIGHT_DAY); + expect(getTrackBackground(true, 10)).toEqual(COLORS.DARK_DAY); }); it('returns a linear gradient with night time sets when sets are provided', () => { diff --git a/web/src/features/charts/bar-breakdown/utils.test.ts b/web/src/features/charts/bar-breakdown/utils.test.ts index 82e13a142a..cb5b1ab1cc 100644 --- a/web/src/features/charts/bar-breakdown/utils.test.ts +++ b/web/src/features/charts/bar-breakdown/utils.test.ts @@ -1,3 +1,5 @@ +import { describe, expect, it } from 'vitest'; + import { convertPrice, ExchangeDataType, @@ -229,7 +231,7 @@ describe('getProductionData', () => { it('returns correct data', () => { const result = getProductionData(zoneDetailsData); // TODO: Match snapshot - expect(result).to.deep.eq(productionData); + expect(result).toEqual(productionData); }); }); @@ -241,7 +243,7 @@ describe('getElectricityProductionValue', () => { production: 500, storage: 0, }); - expect(result).to.eq(500); + expect(result).toEqual(500); }); it('handles missing production value with zero capacity', () => { const result = getElectricityProductionValue({ @@ -250,7 +252,7 @@ describe('getElectricityProductionValue', () => { production: null, storage: 0, }); - expect(result).to.eq(0); + expect(result).toEqual(0); }); it('handles missing production value', () => { @@ -261,7 +263,7 @@ describe('getElectricityProductionValue', () => { storage: 0, }); - expect(result).to.eq(null); + expect(result).toEqual(null); }); it('handles storage', () => { const result = getElectricityProductionValue({ @@ -270,7 +272,7 @@ describe('getElectricityProductionValue', () => { production: null, storage: 300, }); - expect(result).to.eq(-300); + expect(result).toEqual(-300); }); it('handles zero storage', () => { const result = getElectricityProductionValue({ @@ -279,7 +281,7 @@ describe('getElectricityProductionValue', () => { production: null, storage: 0, }); - expect(result).to.eq(0); + expect(result).toEqual(0); }); it('handles missing storage', () => { const result = getElectricityProductionValue({ @@ -288,14 +290,14 @@ describe('getElectricityProductionValue', () => { production: null, storage: null, }); - expect(result).to.eq(null); + expect(result).toEqual(null); }); }); describe('getDataBlockPositions', () => { it('returns correct data', () => { const result = getDataBlockPositions(productionData.length, exchangeData); - expect(result).to.deep.eq({ + expect(result).toEqual({ exchangeFlagX: 50, exchangeHeight: 40, exchangeY: 262, @@ -314,7 +316,7 @@ describe('getExchangesToDisplay', () => { }, }; const result = getExchangesToDisplay(true, 'DE', ZoneStates); - expect(result).to.deep.eq(['AT', 'BE', 'NO']); + expect(result).toEqual(['AT', 'BE', 'NO']); }); it('shows non-aggregated exchanges only when required', () => { const ZoneStates = { @@ -324,7 +326,7 @@ describe('getExchangesToDisplay', () => { }, }; const result = getExchangesToDisplay(false, 'DE', ZoneStates); - expect(result).to.deep.eq(['AT', 'BE', 'NO-NO2']); + expect(result).toEqual(['AT', 'BE', 'NO-NO2']); }); it('handles empty exchange', () => { const ZoneStates = { @@ -334,7 +336,7 @@ describe('getExchangesToDisplay', () => { }, }; const result = getExchangesToDisplay(false, 'DE', ZoneStates); - expect(result).to.deep.eq([]); + expect(result).toEqual([]); }); }); @@ -348,7 +350,7 @@ describe('getExchangeData', () => { }; const result = getExchangeData(['ES', 'AT'], true, exchangeCapacitiesZoneDetailsData); - expect(result).to.deep.eq([ + expect(result).toEqual([ { exchange: 934, exchangeCapacityRange: [-1000, 1000], @@ -371,7 +373,7 @@ describe('getExchangeData', () => { }; const result = getExchangeData(['ES'], true, exchangeCapacitiesZoneDetailsData); - expect(result).to.deep.eq([ + expect(result).toEqual([ { exchange: -934, exchangeCapacityRange: [0, 0], @@ -390,7 +392,7 @@ describe('getExchangeData', () => { }; const result = getExchangeData(['ES'], true, exchangeCapacitiesZoneDetailsData); - expect(result).to.deep.equal([ + expect(result).toEqual([ { exchange: undefined, exchangeCapacityRange: [0, 0], @@ -411,7 +413,7 @@ describe('getExchangeCo2Intensity', () => { }; const result = getExchangeCo2Intensity('ES', exchangeCapacitiesZoneDetailsData, true); - expect(result).to.eq(999); + expect(result).toEqual(999); }); describe('when exchange value is less than 0', () => { it('returns Co2 insensity when in Consumption mode', () => { @@ -426,7 +428,7 @@ describe('getExchangeCo2Intensity', () => { exchangeCapacitiesZoneDetailsData, true ); - expect(result).to.eq(187.32); + expect(result).toEqual(187.32); }); it('returns Co2 insensity production when in Production mode', () => { const exchangeCapacitiesZoneDetailsData = { @@ -440,7 +442,7 @@ describe('getExchangeCo2Intensity', () => { exchangeCapacitiesZoneDetailsData, false ); - expect(result).to.eq(190.6); + expect(result).toEqual(190.6); }); }); }); @@ -448,26 +450,26 @@ describe('getExchangeCo2Intensity', () => { describe('convertPrice', () => { it('dont convert USD to price/KWh', () => { const result = convertPrice(120, 'USD'); - expect(result).to.deep.eq({ value: 120, currency: 'USD', unit: 'MWh' }); + expect(result).toEqual({ value: 120, currency: 'USD', unit: 'MWh' }); }); it('handles missing currency', () => { const result = convertPrice(120, undefined); - expect(result).to.deep.eq({ value: 120, currency: undefined, unit: 'MWh' }); + expect(result).toEqual({ value: 120, currency: undefined, unit: 'MWh' }); }); it('handles missing price with EUR', () => { const result = convertPrice(undefined, 'EUR'); - expect(result).to.deep.eq({ value: undefined, currency: 'EUR', unit: 'MWh' }); + expect(result).toEqual({ value: undefined, currency: 'EUR', unit: 'MWh' }); }); it('handles missing price without EUR', () => { const result = convertPrice(undefined, 'USD'); - expect(result).to.deep.eq({ value: undefined, currency: 'USD', unit: 'MWh' }); + expect(result).toEqual({ value: undefined, currency: 'USD', unit: 'MWh' }); }); it('handles missing price and currency', () => { const result = convertPrice(undefined, undefined); - expect(result).to.deep.eq({ value: undefined, currency: undefined, unit: 'MWh' }); + expect(result).toEqual({ value: undefined, currency: undefined, unit: 'MWh' }); }); }); diff --git a/web/src/features/charts/futurePriceUtils.test.ts b/web/src/features/charts/futurePriceUtils.test.ts index b0d04f6be6..61cb2972a5 100644 --- a/web/src/features/charts/futurePriceUtils.test.ts +++ b/web/src/features/charts/futurePriceUtils.test.ts @@ -1,3 +1,5 @@ +import { describe, expect } from 'vitest'; + import { calculatePriceBound, dateIsFirstHourOfTomorrow, @@ -13,28 +15,28 @@ describe('FuturePrice Utility Functions', () => { const date = new Date('2024-09-02T03:35:00Z'); const granularity = 30; const normalizedDate = normalizeToGranularity(date, granularity); - expect(normalizedDate.getMinutes()).to.equal(30); - expect(normalizedDate.getSeconds()).to.equal(0); + expect(normalizedDate.getMinutes()).toEqual(30); + expect(normalizedDate.getSeconds()).toEqual(0); }); test('normalizeToGranularity should round down to hours', () => { const date = new Date('2024-09-02T03:35:00Z'); const granularity = 60; const normalizedDate = normalizeToGranularity(date, granularity); - expect(normalizedDate.getMinutes()).to.equal(0); - expect(normalizedDate.getSeconds()).to.equal(0); + expect(normalizedDate.getMinutes()).toEqual(0); + expect(normalizedDate.getSeconds()).toEqual(0); }); test('dateIsFirstHourOfTomorrow returns true only is the first hour of the next day', () => { const tomorrow = new Date(); tomorrow.setHours(0, 0, 0, 0); tomorrow.setDate(tomorrow.getDate() + 1); - expect(dateIsFirstHourOfTomorrow(tomorrow)).to.equal(true); + expect(dateIsFirstHourOfTomorrow(tomorrow)).toEqual(true); const tomorrowPlusHalfAnHour = new Date(); tomorrowPlusHalfAnHour.setHours(0, 30, 0, 0); tomorrowPlusHalfAnHour.setDate(tomorrow.getDate() + 1); - expect(dateIsFirstHourOfTomorrow(tomorrowPlusHalfAnHour)).to.equal(false); + expect(dateIsFirstHourOfTomorrow(tomorrowPlusHalfAnHour)).toEqual(false); }); test('filterPriceData filters out the dates that doesnt match the granularity', () => { @@ -45,7 +47,7 @@ describe('FuturePrice Utility Functions', () => { }; const granularity = 60; const filteredData = filterPriceData(priceData, granularity); - expect(Object.keys(filteredData).length).to.equal(2); + expect(Object.keys(filteredData).length).toEqual(2); }); test('getGranularity returns time granularity of the data', () => { @@ -55,7 +57,7 @@ describe('FuturePrice Utility Functions', () => { '2024-09-02T04:00:00Z': 30, }; const granularity = getGranularity(priceData); - expect(granularity).to.equal(30); + expect(granularity).toEqual(30); }); test('calculatePriceBound returns highest and lowest price in dataset', () => { @@ -67,24 +69,24 @@ describe('FuturePrice Utility Functions', () => { const granularity = 15; const minPrice = calculatePriceBound(priceData, Math.min, granularity); - expect(minPrice).to.equal(-10); + expect(minPrice).toEqual(-10); const maxPrice = calculatePriceBound(priceData, Math.max, granularity); - expect(maxPrice).to.equal(30); + expect(maxPrice).toEqual(30); }); test('negativeToPostivePercentage returns the correct percentage of negative to postive ratio', () => { const minPrice = -10; const maxPrice = 20; const percentage = negativeToPostivePercentage(minPrice, maxPrice); - expect(percentage).to.equal(33); + expect(percentage).toEqual(33); }); test('negativeToPostivePercentage returns 0 if the min is above 0', () => { const minPrice = 10; const maxPrice = 20; const percentage = negativeToPostivePercentage(minPrice, maxPrice); - expect(percentage).to.equal(0); + expect(percentage).toEqual(0); }); test('priceIn5Percentile returns true if price is in top 5 percentile', () => { @@ -93,7 +95,7 @@ describe('FuturePrice Utility Functions', () => { const minPrice = 0; const inTop = true; const result = priceIn5Percentile(price, maxPrice, minPrice, inTop); - expect(result).to.equal(true); + expect(result).toEqual(true); }); test('priceIn5Percentile returns false if price is not in top 5 percentile', () => { @@ -102,7 +104,7 @@ describe('FuturePrice Utility Functions', () => { const minPrice = 50; const inTop = true; const result = priceIn5Percentile(price, maxPrice, minPrice, inTop); - expect(result).to.equal(false); + expect(result).toEqual(false); }); test('priceIn5Percentile returns true if price is in bottom 5 percentile', () => { @@ -111,7 +113,7 @@ describe('FuturePrice Utility Functions', () => { const minPrice = 50; const inTop = false; const result = priceIn5Percentile(price, maxPrice, minPrice, inTop); - expect(result).to.equal(true); + expect(result).toEqual(true); }); test('priceIn5Percentile returns false if price is not in bottom 5 percentile', () => { @@ -120,6 +122,6 @@ describe('FuturePrice Utility Functions', () => { const minPrice = 50; const inTop = false; const result = priceIn5Percentile(price, maxPrice, minPrice, inTop); - expect(result).to.equal(false); + expect(result).toEqual(false); }); }); diff --git a/web/src/features/charts/graphUtils.test.ts b/web/src/features/charts/graphUtils.test.ts index 15899735dd..52d6778a22 100644 --- a/web/src/features/charts/graphUtils.test.ts +++ b/web/src/features/charts/graphUtils.test.ts @@ -98,7 +98,7 @@ describe('getRatioPercent', () => { [5, null, '?'], ])('handles %s of %s', (a, b, expected) => { const actual = getRatioPercent(a, b); - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); }); @@ -159,7 +159,7 @@ describe('getElectricityProductionValue', () => { generationTypeStorage: undefined, generationTypeProduction: 41_161, }); - expect(actual).to.deep.eq(41_161); + expect(actual).toEqual(41_161); }); it('handles storage', () => { @@ -169,7 +169,7 @@ describe('getElectricityProductionValue', () => { generationTypeStorage: -3738.75, generationTypeProduction: 11_930.25, }); - expect(actual).to.deep.eq(3738.75); + expect(actual).toEqual(3738.75); }); it('handles missing storage', () => { @@ -179,7 +179,7 @@ describe('getElectricityProductionValue', () => { generationTypeStorage: null, generationTypeProduction: 999, }); - expect(actual).to.deep.eq(null); + expect(actual).toEqual(null); }); it('handles zero storage', () => { @@ -189,7 +189,7 @@ describe('getElectricityProductionValue', () => { generationTypeStorage: 0, generationTypeProduction: 999, }); - expect(actual).to.deep.eq(0); + expect(actual).toEqual(0); }); it('handles zero production', () => { @@ -199,7 +199,7 @@ describe('getElectricityProductionValue', () => { generationTypeStorage: undefined, generationTypeProduction: 0, }); - expect(actual).to.deep.eq(0); + expect(actual).toEqual(0); }); it('handles null production', () => { @@ -209,7 +209,7 @@ describe('getElectricityProductionValue', () => { generationTypeStorage: undefined, generationTypeProduction: null, }); - expect(actual).to.deep.eq(null); + expect(actual).toEqual(null); }); it('handles zero capacity', () => { @@ -219,7 +219,7 @@ describe('getElectricityProductionValue', () => { generationTypeStorage: undefined, generationTypeProduction: 0, }); - expect(actual).to.deep.eq(0); + expect(actual).toEqual(0); }); }); @@ -237,17 +237,17 @@ describe('getTotalEmissionsAvailable and ElectricityAvailable', () => { it('handles emissions for consumption', () => { const actual = getTotalEmissionsAvailable(zoneData, true); - expect(actual).to.deep.eq(175); + expect(actual).toEqual(175); }); it('handles power for consumption', () => { const actual = getTotalElectricityAvailable(zoneData, true); - expect(actual).to.deep.eq(350); + expect(actual).toEqual(350); }); it('handles emissions for production', () => { const actual = getTotalEmissionsAvailable(zoneData, false); - expect(actual).to.deep.eq(150); + expect(actual).toEqual(150); }); it('returns NaN when missing productionValue', () => { @@ -255,12 +255,12 @@ describe('getTotalEmissionsAvailable and ElectricityAvailable', () => { { ...zoneData, totalCo2Production: null } as unknown as ZoneDetail, false ); - expect(actual).to.deep.eq(Number.NaN); + expect(actual).toEqual(Number.NaN); }); it('handles power for production', () => { const actual = getTotalElectricityAvailable(zoneData, false); - expect(actual).to.deep.eq(250); + expect(actual).toEqual(250); }); it('returns 0 when productionValue is 0', () => { @@ -268,7 +268,7 @@ describe('getTotalEmissionsAvailable and ElectricityAvailable', () => { { ...zoneData, totalProduction: 0, totalDischarge: 0 }, false ); - expect(actual).to.deep.eq(0); + expect(actual).toEqual(0); }); it('returns NaN when missing productionValue', () => { @@ -276,7 +276,7 @@ describe('getTotalEmissionsAvailable and ElectricityAvailable', () => { { ...zoneData, totalProduction: null }, false ); - expect(actual).to.deep.eq(Number.NaN); + expect(actual).toEqual(Number.NaN); }); }); @@ -288,32 +288,32 @@ describe('extractLinkFromSource', () => { }; it('should return mapped link if source is in sourceLinkMapping', () => { - expect(extractLinkFromSource('source1', sourceLinkMapping)).to.equal( + expect(extractLinkFromSource('source1', sourceLinkMapping)).toEqual( 'http://mappedlink1.com' ); - expect(extractLinkFromSource('source2', sourceLinkMapping)).to.equal( + expect(extractLinkFromSource('source2', sourceLinkMapping)).toEqual( 'http://mappedlink2.com' ); }); it('should work with a real link', () => { - expect(extractLinkFromSource('Climatescope', sourceLinkMapping)).to.equal( + expect(extractLinkFromSource('Climatescope', sourceLinkMapping)).toEqual( 'https://www.global-climatescope.org/' ); }); it('should return null if source does not include a dot', () => { - expect(extractLinkFromSource('sourceWithoutDot', sourceLinkMapping)).to.be.null; + expect(extractLinkFromSource('sourceWithoutDot', sourceLinkMapping)).toBeNull(); }); it('should return source if source includes http', () => { - expect( - extractLinkFromSource('http://sourceWithHttp.com', sourceLinkMapping) - ).to.equal('http://sourceWithHttp.com'); + expect(extractLinkFromSource('http://sourceWithHttp.com', sourceLinkMapping)).toEqual( + 'http://sourceWithHttp.com' + ); }); it('should return source with http prefix if source includes a dot but not http', () => { - expect(extractLinkFromSource('sourceWithDot.com', sourceLinkMapping)).to.equal( + expect(extractLinkFromSource('sourceWithDot.com', sourceLinkMapping)).toEqual( 'http://sourceWithDot.com' ); }); diff --git a/web/src/features/charts/tooltipCalculations.test.ts b/web/src/features/charts/tooltipCalculations.test.ts index 70a4dbfaca..1fa3354d57 100644 --- a/web/src/features/charts/tooltipCalculations.test.ts +++ b/web/src/features/charts/tooltipCalculations.test.ts @@ -197,13 +197,13 @@ describe('getProductionTooltipData', () => { it('returns 0 usage for zero production', () => { const actual = getProductionTooltipData('solar', zoneDetailsData, false, false); - expect(actual.usage).to.eq(0); - expect(actual.emissions).to.eq(0); + expect(actual.usage).toEqual(0); + expect(actual.emissions).toEqual(0); }); it('returns nan usage for null production', () => { const actual = getProductionTooltipData('geothermal', zoneDetailsData, false, false); - expect(actual.usage).to.be.NaN; + expect(actual.usage).toBeNaN(); }); it('handles data with all production modes missing', () => { @@ -250,7 +250,7 @@ describe('getProductionTooltipData', () => { false ); - expect(actual.usage).to.eq(41_161); + expect(actual.usage).toEqual(41_161); }); }); diff --git a/web/src/features/weather-layers/solar/utils.test.ts b/web/src/features/weather-layers/solar/utils.test.ts index 1e6cae4413..b20419facc 100644 --- a/web/src/features/weather-layers/solar/utils.test.ts +++ b/web/src/features/weather-layers/solar/utils.test.ts @@ -1,3 +1,5 @@ +import { describe, expect, it } from 'vitest'; + import { opacityToSolarIntensity, solarColor, @@ -9,37 +11,37 @@ import { describe('splitRGBA', () => { it('works with rgb()', () => { const result = splitRGBA('rgb(255, 0, 0)'); - expect(result).to.deep.eq([255, 0, 0, 1]); + expect(result).toEqual([255, 0, 0, 1]); }); it('works with rgba()', () => { const result = splitRGBA('rgb(255, 0, 0, 0.23)'); - expect(result).to.deep.eq([255, 0, 0, 0.23]); + expect(result).toEqual([255, 0, 0, 0.23]); }); }); describe('solarColor', () => { it('works', () => { const result = solarColor(97); - expect(result).to.deep.eq('rgba(0, 0, 0, 0.806)'); + expect(result).toEqual('rgba(0, 0, 0, 0.806)'); }); }); describe('solarIntensityToOpacity', () => { it('works', () => { const result = solarIntensityToOpacity(97); - expect(result).to.deep.eq(24); + expect(result).toEqual(24); }); }); describe('opacityToSolarIntensity', () => { it('works', () => { const result = opacityToSolarIntensity(97); - expect(result).to.deep.eq(380); + expect(result).toEqual(380); }); }); describe('solarColorComponents', () => { it('works ', () => { const result = solarColorComponents[380]; - expect(result).to.deep.eq({ alpha: 52, blue: 0, green: 0, red: 0 }); + expect(result).toEqual({ alpha: 52, blue: 0, green: 0, red: 0 }); }); }); diff --git a/web/src/features/weather-layers/wind-layer/calc.test.ts b/web/src/features/weather-layers/wind-layer/calc.test.ts index 7329b4c57c..09eb9d5f8a 100644 --- a/web/src/features/weather-layers/wind-layer/calc.test.ts +++ b/web/src/features/weather-layers/wind-layer/calc.test.ts @@ -1,4 +1,5 @@ import { round } from 'utils/helpers'; +import { describe, expect, it } from 'vitest'; import { bilinearInterpolateVector, buildBounds, distort } from './calc'; @@ -19,7 +20,7 @@ describe('bilinearInterpolateVector', () => { g11 ); const result = [result1, result2, round(result3, 13)]; - expect(result).to.deep.eq([4, 5, round(Math.sqrt(41), 13)]); + expect(result).toEqual([4, 5, round(Math.sqrt(41), 13)]); }); it('should interpolate a vector at the top left corner of the square', () => { @@ -38,7 +39,7 @@ describe('bilinearInterpolateVector', () => { g11 ); const result = [result1, result2, round(result3, 13)]; - expect(result).to.deep.eq([1, 2, round(Math.sqrt(5), 13)]); + expect(result).toEqual([1, 2, round(Math.sqrt(5), 13)]); }); it('should interpolate a vector at the top right corner of the square', () => { @@ -57,7 +58,7 @@ describe('bilinearInterpolateVector', () => { g11 ); const result = [result1, result2, round(result3, 13)]; - expect(result).to.deep.eq([3, 4, 5]); + expect(result).toEqual([3, 4, 5]); }); it('should interpolate a vector at the bottom left corner of the square', () => { @@ -76,7 +77,7 @@ describe('bilinearInterpolateVector', () => { g11 ); const result = [result1, result2, round(result3, 13)]; - expect(result).to.deep.eq([5, 6, round(Math.sqrt(61), 13)]); + expect(result).toEqual([5, 6, round(Math.sqrt(61), 13)]); }); it('should interpolate a vector at the bottom right corner of the square', () => { @@ -95,7 +96,7 @@ describe('bilinearInterpolateVector', () => { g11 ); const result = [result1, result2, round(result3, 13)]; - expect(result).to.deep.eq([7, 8, round(Math.sqrt(113), 13)]); + expect(result).toEqual([7, 8, round(Math.sqrt(113), 13)]); }); }); @@ -136,25 +137,25 @@ describe('distort', () => { 0.006_120_000_000_000_000_4, [0.551_289_441_234_658_4, -0.174_103_992_708_016_4, 11.492_476_595_423_65] ); - expect(isFloatClose(u, 0.027_732_572_562_027_27)).to.be.true; - expect(isFloatClose(v, 0.008_758_287_040_257)).to.be.true; - expect(isFloatClose(m, 11.492_476_595_423_65)).to.be.true; + expect(isFloatClose(u, 0.027_732_572_562_027_27)).toBe(true); + expect(isFloatClose(v, 0.008_758_287_040_257)).toBe(true); + expect(isFloatClose(m, 11.492_476_595_423_65)).toBe(true); }); it('test custom project', () => { const result = distort(mapMock, 0, 0, 0, 0, 1, [1, 1, 1]); // This result is mainly used as reference for following tests - expect(result).to.deep.eq([2, 2, 1]); + expect(result).toEqual([2, 2, 1]); }); it('test scale using custom project', () => { const result = distort(mapMock, 0, 0, 0, 0, 2, [1, 1, 3]); - expect(result).to.deep.eq([4, 4, 3]); + expect(result).toEqual([4, 4, 3]); }); it('test non-zero x and y bounds using custom project', () => { const result = distort(mapMock, 0, 0, -H, -H, 1, [1, 1, 7]); - expect(result).to.deep.eq([-0, -0, 7]); + expect(result).toEqual([-0, -0, 7]); }); }); @@ -168,7 +169,7 @@ describe('buildBounds', () => { const height = 765; const result = buildBounds(bounds, width, height); - expect(result).to.deep.eq({ x: 0, y: 0, yMax: 764, width: 821, height: 765 }); + expect(result).toEqual({ x: 0, y: 0, yMax: 764, width: 821, height: 765 }); }); it('handles unexpected dimension values', () => { @@ -180,7 +181,7 @@ describe('buildBounds', () => { const height = 50; const result = buildBounds(bounds, width, height); - expect(result).to.deep.eq({ x: 1, y: 0, yMax: 49, width: 100, height: 50 }); + expect(result).toEqual({ x: 1, y: 0, yMax: 49, width: 100, height: 50 }); }); it('handles decimals', () => { @@ -192,6 +193,6 @@ describe('buildBounds', () => { const height = 6.9; const result = buildBounds(bounds, width, height); - expect(result).to.deep.eq({ x: 1, y: 2, yMax: 5.9, width: 5.8, height: 6.9 }); + expect(result).toEqual({ x: 1, y: 2, yMax: 5.9, width: 5.8, height: 6.9 }); }); }); diff --git a/web/src/features/weather-layers/wind-layer/windy.test.ts b/web/src/features/weather-layers/wind-layer/windy.test.ts index e358fe4739..06a22f54e1 100644 --- a/web/src/features/weather-layers/wind-layer/windy.test.ts +++ b/web/src/features/weather-layers/wind-layer/windy.test.ts @@ -1,10 +1,12 @@ +import { describe, expect, it } from 'vitest'; + import { windIntensityColorScale } from './scales'; describe('windIntensityColorScale', () => { it('should return an array of colors', () => { const result = windIntensityColorScale(); - expect(Array.isArray(result)).to.be.true; - expect(result.length).to.be.greaterThan(0); - expect(typeof result[0]).to.eq('string'); + expect(Array.isArray(result)).toBe(true); + expect(result.length).toBeGreaterThan(0); + expect(typeof result[0]).toEqual('string'); }); }); diff --git a/web/src/hooks/nightTimes.test.ts b/web/src/hooks/nightTimes.test.ts index 955c7112ed..06595a3602 100644 --- a/web/src/hooks/nightTimes.test.ts +++ b/web/src/hooks/nightTimes.test.ts @@ -1,3 +1,5 @@ +import { describe, expect, it } from 'vitest'; + import { calculateNightTimes } from './nightTimes'; function createDatetimes(start: Date) { @@ -14,14 +16,14 @@ describe('calculateNightTimes', () => { const latitude = -38.253; const longitude = 146.575; const result = calculateNightTimes(datetimes, latitude, longitude); - expect(result).to.deep.eq([[7, 21]]); + expect(result).toEqual([[7, 21]]); }); it('should handle multiple nights during the period', () => { const datetimes = createDatetimes(new Date('2023-06-01T12:00:00')); const latitude = -38.253; const longitude = 146.575; const result = calculateNightTimes(datetimes, latitude, longitude); - expect(result).to.deep.eq([ + expect(result).toEqual([ [0, 11], [21, 24], ]); diff --git a/web/src/translation/translation.test.ts b/web/src/translation/translation.test.ts index 1efb05c4b0..ac0601d386 100644 --- a/web/src/translation/translation.test.ts +++ b/web/src/translation/translation.test.ts @@ -14,7 +14,7 @@ describe('translateIfExists', () => { const translation = translateIfExists('zoneShortName.AT.zoneName'); - expect(translation).to.equal('Austria'); + expect(translation).toEqual('Austria'); }); it('should return an empty string if the key does not exist', () => {}); @@ -23,7 +23,7 @@ describe('translateIfExists', () => { const translation = translateIfExists('zoneShortName.AT.zoneName'); - expect(translation).to.equal(''); + expect(translation).toEqual(''); }); // TODO: Mocking these tests is currently not possible or easy due to the translation diff --git a/web/src/utils/formatting.test.ts b/web/src/utils/formatting.test.ts index fded5320f8..2a8b5eda43 100644 --- a/web/src/utils/formatting.test.ts +++ b/web/src/utils/formatting.test.ts @@ -17,139 +17,139 @@ describe('formatEnergy', () => { it('handles NaN input', () => { const actual = formatEnergy({ value: Number.NaN }); const expected = Number.NaN; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles custom number of digits', () => { const actual = formatEnergy({ value: 1.234_567, numberDigits: 4 }); const expected = '1.235 MWh'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles default number kWh', () => { const actual = formatEnergy({ value: 0.002_234_567 }); const expected = '2.23 kWh'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles MWh', () => { const actual = formatEnergy({ value: 1.234_567 }); const expected = '1.23 MWh'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles GWh', () => { const actual = formatEnergy({ value: 1222.234_567 }); const expected = '1.22 GWh'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles TWh', () => { const actual = formatEnergy({ value: 1_222_000.234_567 }); const expected = '1.22 TWh'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('Converts PWh to TWh', () => { const actual = formatEnergy({ value: 1_222_000_000.234_567 }); const expected = '1220 TWh'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles zero input', () => { const actual = formatEnergy({ value: 0 }); const expected = '0 Wh'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles 1 input for number of digits', () => { const actual = formatEnergy({ value: 12_313, numberDigits: 1 }); const expected = '10 GWh'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles 0 input for number of digits', () => { const actual = formatEnergy({ value: 12_313, numberDigits: 0 }); const expected = '10 GWh'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for W', () => { const actual = formatPower({ value: 0.000_05, total: 0.0006 }); const expected = '50 W'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for W with decimal', () => { const actual = formatPower({ value: 0.000_054_6, total: 0.0006 }); const expected = '54.6 W'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for kW', () => { const actual = formatPower({ value: 0.003, total: 0.05 }); const expected = '3 kW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for kW with decimal', () => { const actual = formatPower({ value: 0.000_05, total: 0.05 }); const expected = '0.05 kW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles value and total being the same', () => { const actual = formatPower({ value: 0.05, total: 0.05 }); const expected = '50 kW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for MW', () => { const actual = formatPower({ value: 0.009, total: 30 }); const expected = '0.009 MW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for GW', () => { const actual = formatPower({ value: 6.5, total: 70_000 }); const expected = '0.0065 GW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for GW with value being small', () => { const actual = formatPower({ value: 0.000_05, total: 70_000 }); const expected = '0.00000005 GW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for GW with value being very small', () => { const actual = formatPower({ value: 0.000_000_05, total: 70_000 }); const expected = '~0 W'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for GW with value being 0', () => { const actual = formatPower({ value: 0, total: 70_000 }); const expected = '0 W'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for TW', () => { const actual = formatPower({ value: 45, total: 890_000_000 }); const expected = '0.000045 TW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for TW with small value', () => { const actual = formatPower({ value: 0.000_05, total: 890_000_000 }); const expected = '0.00000000005 TW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles using same unit as total for TW with a precise number', () => { const actual = formatPower({ value: 42_059.836_85, total: 890_000_000 }); const expected = '0.0421 TW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); }); @@ -157,55 +157,55 @@ describe('formatPower', () => { it('handles NaN input', () => { const actual = formatPower({ value: Number.NaN }); const expected = Number.NaN; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles custom number of digits', () => { const actual = formatPower({ value: 1.234_567, numberDigits: 4 }); const expected = '1.235 MW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles default number kW', () => { const actual = formatPower({ value: 0.002_234_567 }); const expected = '2.23 kW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles MW', () => { const actual = formatPower({ value: 1.234_567 }); const expected = '1.23 MW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles GW', () => { const actual = formatPower({ value: 1222.234_567 }); const expected = '1.22 GW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles TW', () => { const actual = formatPower({ value: 1_222_000.234_567 }); const expected = '1.22 TW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles zero input', () => { const actual = formatPower({ value: 0 }); const expected = '0 W'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles 1 input for number of digits', () => { const actual = formatPower({ value: 12_313, numberDigits: 1 }); const expected = '10 GW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles 0 input for number of digits', () => { const actual = formatPower({ value: 12_313, numberDigits: 0 }); const expected = '10 GW'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); }); @@ -213,144 +213,144 @@ describe('formatCo2', () => { it('handles NaN input', () => { const actual = formatCo2({ value: Number.NaN }); const expected = '?'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles undefined input', () => { const actual = formatCo2({ value: undefined as unknown as number }); const expected = '?'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles null input', () => { const actual = formatCo2({ value: null as unknown as number }); const expected = '?'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles grams', () => { const actual = formatCo2({ value: 20 }); const expected = '20 g'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles kilograms', () => { const actual = formatCo2({ value: 1000 }); const expected = '1 kg'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles tonnes', () => { const actual = formatCo2({ value: 1_000_000 }); const expected = '1 t'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('uses same unit as another value would', () => { const actual = formatCo2({ value: 23_500, total: 2_350_000 }); const expected = '0.0235 t'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('adds decimals if comparing with tonnes', () => { const actual = formatCo2({ value: 200_500, total: 2_350_000 }); const expected = '0.201 t'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('adds decimals if comparing with large tonnes', () => { const actual = formatCo2({ value: 200_500, total: 992_350_000 }); const expected = '0.201 t'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles real data value', () => { const actual = formatCo2({ value: 740_703_650 }); const expected = '741 t'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles kilotonnes', () => { const actual = formatCo2({ value: 99_000_000_000 }); const expected = '99 kt'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles megatonnes', () => { const actual = formatCo2({ value: 99_000_000_000_000 }); const expected = '99 Mt'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles megatonnes close to 1Gt rounding down', () => { const actual = formatCo2({ value: 994_320_320_231_123 }); const expected = '994 Mt'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles values up to 1 trillion grams, rounding up', () => { const actual = formatCo2({ value: 999_900_000_000_000 }); const expected = '1000 Mt'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles values above 1 trillion', () => { const actual = formatCo2({ value: 6_700_000_000_000_000 }); const expected = '6.7 Gt'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles values petatonnes', () => { const actual = formatCo2({ value: 1.5e21 }); const expected = '1500 Tt'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles negative values g', () => { const actual = formatCo2({ value: -9 }); const expected = '−9 g'; - expect(actual).to.eq(expected); + expect(actual).toEqual(expected); }); it('handles negative values kg', () => { const actual = formatCo2({ value: -9000 }); const expected = '−9 kg'; - expect(actual).to.eq(expected); + expect(actual).toEqual(expected); }); it('handles negative values t', () => { const actual = formatCo2({ value: -9_000_000 }); const expected = '−9 t'; - expect(actual).to.eq(expected); + expect(actual).toEqual(expected); }); it('handles negative values kt', () => { const actual = formatCo2({ value: -9_000_000_000 }); const expected = '−9 kt'; - expect(actual).to.eq(expected); + expect(actual).toEqual(expected); }); it('handles negative values Mt', () => { const actual = formatCo2({ value: -99_000_000_000_000 }); const expected = '−99 Mt'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('uses same unit as another value would - negative t', () => { const actual = formatCo2({ value: -23_000, total: -2_350_000 }); const expected = '−0.023 t'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('uses same unit as another value would - negative kg', () => { const actual = formatCo2({ value: -23_000, total: -24_000 }); const expected = '−23 kg'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles real data value - negative', () => { const actual = formatCo2({ value: -740_703_650 }); const expected = '−741 t'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles values petatonnes - negative', () => { const actual = formatCo2({ value: -1.5e21 }); const expected = '−1500 Tt'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles megatonnes close to 1Gt rounding down - negative', () => { const actual = formatCo2({ value: -994_320_320_231_123 }); const expected = '−994 Mt'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles values up to 1 trillion grams, rounding up - negative', () => { const actual = formatCo2({ value: -999_900_000_000_000 }); const expected = '−1000 Mt'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles negative values correct when value to match is positive', () => { const actual = formatCo2({ value: -1_400_000_000, total: 1_400_000_000 }); const expected = '−1.4 kt'; - expect(actual).to.eq(expected); + expect(actual).toEqual(expected); }); }); @@ -366,7 +366,7 @@ describe('getDateTimeFormatOptions', () => { timeZone: 'UTC', timeZoneName: 'short', }; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles hourly data without timezone', () => { @@ -380,7 +380,7 @@ describe('getDateTimeFormatOptions', () => { timeZone: undefined, timeZoneName: 'short', }; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles daily data', () => { @@ -389,7 +389,7 @@ describe('getDateTimeFormatOptions', () => { dateStyle: 'long', timeZone: 'UTC', }; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles monthly data', () => { const actual = getDateTimeFormatOptions(TimeRange.ALL_MONTHS); @@ -398,7 +398,7 @@ describe('getDateTimeFormatOptions', () => { year: 'numeric', timeZone: 'UTC', }; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles yearly data', () => { const actual = getDateTimeFormatOptions(TimeRange.ALL_YEARS); @@ -406,7 +406,7 @@ describe('getDateTimeFormatOptions', () => { year: 'numeric', timeZone: 'UTC', }; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('logs an error on unknown data', () => { // Spy on console.error to check if it is called @@ -414,7 +414,7 @@ describe('getDateTimeFormatOptions', () => { const actual = getDateTimeFormatOptions('ThisAggregateDoesNotExist' as TimeRange); const expected = {}; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); expect(consoleErrorSpy).toHaveBeenCalledWith( 'ThisAggregateDoesNotExist is not implemented' ); @@ -430,13 +430,13 @@ describe('formatDate', () => { it('handles invalid date', () => { const actual = formatDate(new Date('invalid-date'), 'en', TimeRange.H72); const expected = ''; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it('handles a date that is not a Date object', () => { const actual = formatDate('not-a-date' as unknown as Date, 'en', TimeRange.H72); const expected = ''; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); }); it.each(['en', 'sv', 'de', 'fr', 'es', 'it'])( @@ -493,7 +493,7 @@ describe('formatDate', () => { 'ThisAggregateDoesNotExist' as TimeRange ); const expected = '1/1/2021'; - expect(actual).to.deep.eq(expected); + expect(actual).toEqual(expected); expect(consoleErrorSpy).toHaveBeenCalledWith( 'ThisAggregateDoesNotExist is not implemented' ); diff --git a/web/src/utils/helpers.test.ts b/web/src/utils/helpers.test.ts index bf605796e7..3eecaf6ccc 100644 --- a/web/src/utils/helpers.test.ts +++ b/web/src/utils/helpers.test.ts @@ -26,19 +26,19 @@ import { describe('dateToDatetimeString', () => { it('returns the correct datetime string', () => { const actual = dateToDatetimeString(new Date('2023-01-01T12:00:00Z')); - expect(actual).to.eq('2023-01-01T12:00:00Z'); + expect(actual).toEqual('2023-01-01T12:00:00Z'); }); }); describe('getProductionCo2Intensity', () => { it('returns the correct value when the type is hydro', () => { const actual = getProductionCo2Intensity('hydro', zoneDetailMock); - expect(actual).to.eq(10.7); + expect(actual).toEqual(10.7); }); it('returns the correct value when the type is battery storage', () => { const actual = getProductionCo2Intensity('battery storage', zoneDetailMock); - expect(actual).to.eq(0); + expect(actual).toEqual(0); }); }); @@ -47,27 +47,27 @@ describe('getFossilFuelRatio', () => { describe('consumption', () => { it('returns 1 when fossil fuel ratio is 0', () => { const actual = getFossilFuelRatio({ c: { fr: 0 }, p: { fr: 1 } }, true); - expect(actual).to.eq(1); + expect(actual).toEqual(1); }); it('returns 0 when fossil fuel ratio is 1', () => { const actual = getFossilFuelRatio({ c: { fr: 1 }, p: { fr: 0 } }, true); - expect(actual).to.eq(0); + expect(actual).toEqual(0); }); it('returns NaN when fossil fuel ratio is null', () => { const actual = getFossilFuelRatio({ c: { fr: null }, p: { fr: null } }, true); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); it('returns NaN when fossil fuel ratio is undefined', () => { const actual = getFossilFuelRatio({ c: {}, p: {} }, true); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); it('returns 1 - fossil fuel ratio when fossil fuel ratio is between 0 and 1', () => { const actual = getFossilFuelRatio({ c: { fr: 0.3 }, p: { fr: 0.7 } }, true); - expect(actual).to.eq(0.7); + expect(actual).toEqual(0.7); }); }); @@ -75,27 +75,27 @@ describe('getFossilFuelRatio', () => { describe('production', () => { it('returns 1 when fossil fuel ratio is 0', () => { const actual = getFossilFuelRatio({ c: { fr: 1 }, p: { fr: 0 } }, false); - expect(actual).to.eq(1); + expect(actual).toEqual(1); }); it('returns 0 when fossil fuel ratio is 1', () => { const actual = getFossilFuelRatio({ c: { fr: 0 }, p: { fr: 1 } }, false); - expect(actual).to.eq(0); + expect(actual).toEqual(0); }); it('returns NaN when fossil fuel ratio is null', () => { const actual = getFossilFuelRatio({ c: { fr: null }, p: { fr: null } }, false); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); it('returns NaN when fossil fuel ratio is undefined', () => { const actual = getFossilFuelRatio({ c: {}, p: {} }, false); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); it('returns 1 - fossil fuel ratio when fossil fuel ratio is between 0 and 1', () => { const actual = getFossilFuelRatio({ c: { fr: 0.7 }, p: { fr: 0.3 } }, false); - expect(actual).to.eq(0.7); + expect(actual).toEqual(0.7); }); }); }); @@ -105,17 +105,17 @@ describe('getCarbonIntensity', () => { describe('consumption', () => { it('returns carbon intensity when carbon intensity is not null', () => { const actual = getCarbonIntensity({ c: { ci: 100 }, p: { ci: 200 } }, true); - expect(actual).to.eq(100); + expect(actual).toEqual(100); }); it('returns NaN when carbon intensity is null', () => { const actual = getCarbonIntensity({ c: { fr: null }, p: { fr: null } }, true); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); it('returns NaN when carbon intensity is undefined', () => { const actual = getCarbonIntensity({ c: {}, p: {} }, true); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); }); @@ -123,17 +123,17 @@ describe('getCarbonIntensity', () => { describe('production', () => { it('returns carbon intensity when carbon intensity is not null', () => { const actual = getCarbonIntensity({ c: { ci: 100 }, p: { ci: 200 } }, false); - expect(actual).to.eq(200); + expect(actual).toEqual(200); }); it('returns NaN when carbon intensity is null', () => { const actual = getCarbonIntensity({ c: { fr: null }, p: { fr: null } }, false); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); it('returns NaN when carbon intensity is undefined', () => { const actual = getCarbonIntensity({ c: {}, p: {} }, false); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); }); }); @@ -143,17 +143,17 @@ describe('getRenewableRatio', () => { describe('consumption', () => { it('returns renewable ratio when renewable ratio is not null', () => { const actual = getRenewableRatio({ c: { rr: 0.5 }, p: { rr: 0.3 } }, true); - expect(actual).to.eq(0.5); + expect(actual).toEqual(0.5); }); it('returns NaN when renewable ratio is null', () => { const actual = getRenewableRatio({ c: { rr: null }, p: { rr: null } }, true); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); it('returns NaN when renewable ratio is undefined', () => { const actual = getRenewableRatio({ c: {}, p: {} }, true); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); }); @@ -161,17 +161,17 @@ describe('getRenewableRatio', () => { describe('production', () => { it('returns renewable ratio when renewable ratio is not null', () => { const actual = getRenewableRatio({ c: { rr: 0.5 }, p: { rr: 0.3 } }, false); - expect(actual).to.eq(0.3); + expect(actual).toEqual(0.3); }); it('returns NaN when renewable ratio is null', () => { const actual = getRenewableRatio({ c: { rr: null }, p: { rr: null } }, false); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); it('returns NaN when renewable ratio is undefined', () => { const actual = getRenewableRatio({ c: {}, p: {} }, false); - expect(actual).to.be.NaN; + expect(actual).toBeNaN(); }); }); }); diff --git a/web/src/utils/styling.test.ts b/web/src/utils/styling.test.ts index ac71609e71..defa85c4a3 100644 --- a/web/src/utils/styling.test.ts +++ b/web/src/utils/styling.test.ts @@ -1,4 +1,5 @@ import { act, renderHook } from '@testing-library/react'; +import { describe, expect, it } from 'vitest'; import { useMediaQuery } from './styling'; @@ -9,10 +10,10 @@ describe('useMediaQuery', () => { it('renders', () => { window.resizeTo(BELOW_MIN_WIDTH, 0); const { result } = renderHook(() => useMediaQuery(`(min-width: ${MIN_WITDH}px)`)); - expect(result.current).to.be.false; + expect(result.current).toBe(false); act(() => window.resizeTo(MIN_WITDH, 0)); - expect(result.current).to.be.true; + expect(result.current).toBe(true); }); });