From 05d3cc757d8cda49eb1db2271f9dcf5ae528b54a Mon Sep 17 00:00:00 2001 From: Luke Stebner Date: Sun, 14 Jan 2024 15:56:26 -0800 Subject: [PATCH] update some mocks --- .../reducers/processWeather.test.js | 24 +++++++-------- src/game-logic/reducers/purchaseField.test.js | 30 +++++++++---------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/game-logic/reducers/processWeather.test.js b/src/game-logic/reducers/processWeather.test.js index bfe72bcea..e7175343b 100644 --- a/src/game-logic/reducers/processWeather.test.js +++ b/src/game-logic/reducers/processWeather.test.js @@ -1,17 +1,18 @@ import { testCrop } from '../../test-utils' -jest.mock('../../data/maps') +import { shouldPrecipitateToday } from '../../utils' + +import { processWeather } from './processWeather' -// TODO: Dependency-inject external constants rather than mocking them out. +jest.mock('../../data/maps') +jest.mock('../../utils', () => ({ + ...jest.requireActual('../../utils'), + shouldPrecipitateToday: jest.fn(), +})) describe('processWeather', () => { test('does not water plants when there is no precipitation', () => { - jest.resetModules() - jest.mock('../../constants', () => ({ - PRECIPITATION_CHANCE: 0, - })) - - const { processWeather } = jest.requireActual('./processWeather') + shouldPrecipitateToday.mockReturnValue(false) const state = processWeather({ field: [[testCrop()]], @@ -22,12 +23,7 @@ describe('processWeather', () => { }) test('does water plants on a rainy day', () => { - jest.resetModules() - jest.mock('../../constants', () => ({ - PRECIPITATION_CHANCE: 1, - })) - - const { processWeather } = jest.requireActual('./processWeather') + shouldPrecipitateToday.mockReturnValue(true) const state = processWeather({ field: [[testCrop()]], diff --git a/src/game-logic/reducers/purchaseField.test.js b/src/game-logic/reducers/purchaseField.test.js index 7c4edca8b..eee0eac5d 100644 --- a/src/game-logic/reducers/purchaseField.test.js +++ b/src/game-logic/reducers/purchaseField.test.js @@ -1,5 +1,5 @@ import { testCrop } from '../../test-utils' -import { EXPERIENCE_VALUES } from '../../constants' +import { EXPERIENCE_VALUES, PURCHASEABLE_FIELD_SIZES } from '../../constants' import { purchaseField } from './purchaseField' @@ -27,15 +27,16 @@ describe('purchaseField', () => { describe('field expansion', () => { test('field expands without destroying existing data', () => { - jest.resetModules() - jest.mock('../../constants', () => ({ - EXPERIENCE_VALUES: {}, - PURCHASEABLE_FIELD_SIZES: new Map([ - [1, { columns: 3, rows: 4, price: 1000 }], - ]), - })) + const expectedField = [] + const fieldSize = PURCHASEABLE_FIELD_SIZES.get(1) - const { purchaseField } = jest.requireActual('./purchaseField') + for (let y = 0; y < fieldSize.rows; y++) { + const row = [] + for (let x = 0; x < fieldSize.columns; x++) { + row.push(null) + } + expectedField.push(row) + } const { field } = purchaseField( { @@ -46,12 +47,11 @@ describe('purchaseField', () => { }, 1 ) - expect(field).toEqual([ - [testCrop(), null, null], - [null, testCrop(), null], - [null, null, null], - [null, null, null], - ]) + + expectedField[0][0] = testCrop() + expectedField[1][1] = testCrop() + + expect(field).toEqual(expectedField) }) }) })