/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import {render} from '@testing-library/react'; import * as React from 'react'; function Button({label}) { const theme = useTheme(); const style = computeStyle(theme); return ; } let currentTheme = 'light'; function useTheme() { 'use memo'; return currentTheme; } let styleComputations = 0; function computeStyle(theme) { styleComputations++; return theme === 'light' ? 'white' : 'black'; } test('update-button', () => { const {asFragment, rerender} = render( `); // Update the label, but not the theme rerender( `); currentTheme = 'dark'; rerender( `); expect(styleComputations).toBe(__FORGET__ ? 2 : 3); });