/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-native/Libraries/Animated/__tests__/AnimatedObject-test.js
96 строк
2 KB
Tim Yung
RN: Flowify `packages/react-native` Mocks & Tests (#51794)
04 июн 2025, 22:03
04 июн 2025, 22:03
5ce99e7
Код
Авторство
О чём код?
/** * 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 strict-local * @format */ import nullthrows from 'nullthrows'; describe('AnimatedObject', () => { let Animated; let AnimatedObject; beforeEach(() => { jest.resetModules(); Animated = require('../Animated').default; AnimatedObject = require('../nodes/AnimatedObject').default; }); it('should get the proper value', () => { const anim = new Animated.Value(0); const translateAnim = anim.interpolate({ inputRange: [0, 1], outputRange: [100, 200], }); const node = nullthrows( AnimatedObject.from([ { translate: [translateAnim, translateAnim], }, { translateX: translateAnim, }, {scale: anim}, ]), ); expect(node.__getValue()).toEqual([ {translate: [100, 100]}, {translateX: 100}, {scale: 0}, ]); }); it('should make all AnimatedNodes native', () => { const anim = new Animated.Value(0); const translateAnim = anim.interpolate({ inputRange: [0, 1], outputRange: [100, 200], }); const node = nullthrows( AnimatedObject.from([ { translate: [translateAnim, translateAnim], }, { translateX: translateAnim, }, {scale: anim}, ]), ); node.__makeNative(); expect(node.__isNative).toBe(true); expect(anim.__isNative).toBe(true); expect(translateAnim.__isNative).toBe(true); }); it('detects animated nodes', () => { expect(AnimatedObject.from(10)).toBe(null); const anim = new Animated.Value(0); expect(AnimatedObject.from(anim)).not.toBe(null); const event = Animated.event([{}], {useNativeDriver: true}); expect(AnimatedObject.from(event)).toBe(null); expect(AnimatedObject.from([10, 10])).toBe(null); expect(AnimatedObject.from([10, anim])).not.toBe(null); expect(AnimatedObject.from({a: 10, b: 10})).toBe(null); expect(AnimatedObject.from({a: 10, b: anim})).not.toBe(null); expect(AnimatedObject.from({a: 10, b: {ba: 10, bb: 10}})).toBe(null); expect(AnimatedObject.from({a: 10, b: {ba: 10, bb: anim}})).not.toBe(null); expect(AnimatedObject.from({a: 10, b: [10, 10]})).toBe(null); expect(AnimatedObject.from({a: 10, b: [10, anim]})).not.toBe(null); }); });