diff --git a/packages/react-native-web/src/exports/useColorScheme/__tests__/index-test.js b/packages/react-native-web/src/exports/useColorScheme/__tests__/index-test.js new file mode 100644 index 0000000000..14a97af152 --- /dev/null +++ b/packages/react-native-web/src/exports/useColorScheme/__tests__/index-test.js @@ -0,0 +1,38 @@ +/** + * 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. + * + * @flow + */ + +import * as React from 'react'; +import { render } from '@testing-library/react'; +import Appearance from '../../Appearance'; +import useColorScheme from '..'; + +describe('useColorScheme', () => { + test('keeps its subscription active across rerenders', () => { + const remove = jest.fn(); + const addChangeListener = jest + .spyOn(Appearance, 'addChangeListener') + .mockReturnValue({ remove }); + + function Component({ label }): React.Node { + const colorScheme = useColorScheme(); + return