From 6f84221573c322af5727779b235dfbeadbaf5c0e Mon Sep 17 00:00:00 2001 From: Gabriel Clark <> Date: Mon, 13 Sep 2021 11:21:53 -0500 Subject: [PATCH] Added return value mocking to the component unit test. --- .../__snapshots__/numberInputField.test.js.snap | 2 +- .../features/number-input-field/numberInputField.test.js | 7 ++----- unit-conversion/src/setupTests.js | 4 ++++ 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/unit-conversion/src/features/number-input-field/__snapshots__/numberInputField.test.js.snap b/unit-conversion/src/features/number-input-field/__snapshots__/numberInputField.test.js.snap index 331b209..74683fb 100644 --- a/unit-conversion/src/features/number-input-field/__snapshots__/numberInputField.test.js.snap +++ b/unit-conversion/src/features/number-input-field/__snapshots__/numberInputField.test.js.snap @@ -13,7 +13,7 @@ exports[`the NumberInputField component numberInputField displays apropriate con <input class="inputField" id="inputField" - placeholder="Enter # of \\"undefined\\"" + placeholder="Enter # of \\"cm\\"" type="text" /> </div> diff --git a/unit-conversion/src/features/number-input-field/numberInputField.test.js b/unit-conversion/src/features/number-input-field/numberInputField.test.js index 2233098..519d4ca 100644 --- a/unit-conversion/src/features/number-input-field/numberInputField.test.js +++ b/unit-conversion/src/features/number-input-field/numberInputField.test.js @@ -8,11 +8,9 @@ import { setNumberOfUnits, } from './numberInputFieldSlice.js'; -/* import { selectCurrentInputUnit, } from '../unit-selector/unitSelectorSlice.js'; -*/ jest.mock('../unit-selector/unitSelectorSlice.js', () => ({ selectCurrentInputUnit: jest.fn().mockName('selectCurrentInputUnit'), @@ -49,12 +47,11 @@ describe('the NumberInputField slice', () => { describe('the NumberInputField component', () => { test('numberInputField displays apropriate content', () => { - // HOW DO I GET THIS TO WORK???? - // selectCurrentInputUnit.mockReturnValue('cm'); + selectCurrentInputUnit.mockReturnValue('cm'); const { container } = render(<NumberInputField/>); expect(screen.getByLabelText('inputField')).toHaveAttribute( - 'placeholder', expect.stringContaining('Enter # of "undefined"'), + 'placeholder', expect.stringContaining('Enter # of "cm"'), ); expect(container).toMatchSnapshot(); }); diff --git a/unit-conversion/src/setupTests.js b/unit-conversion/src/setupTests.js index 666127a..3563574 100644 --- a/unit-conversion/src/setupTests.js +++ b/unit-conversion/src/setupTests.js @@ -1 +1,5 @@ import '@testing-library/jest-dom/extend-expect'; + +afterEach(() => { + jest.clearAllMocks(); +}); -- GitLab