From 493673f805b3732518f01b06a5b05ab346d9b1e6 Mon Sep 17 00:00:00 2001 From: Aditya Singh Date: Sun, 24 May 2026 09:01:56 -0700 Subject: [PATCH] [react-strict-animated] Fix incorrect error message for invalid mass in SpringAnimation The mass validation in the SpringAnimation constructor threw 'Damping value must be greater than 0', a copy-paste of the preceding damping check. It now reports 'Mass value must be greater than 0', matching the field being validated (and the equivalent check in React Native's SpringAnimation). --- .../src/web/__tests__/SpringAnimation-test.js | 30 +++++++++++++++++++ .../src/web/animations/SpringAnimation.js | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 packages/react-strict-animated/src/web/__tests__/SpringAnimation-test.js diff --git a/packages/react-strict-animated/src/web/__tests__/SpringAnimation-test.js b/packages/react-strict-animated/src/web/__tests__/SpringAnimation-test.js new file mode 100644 index 00000000..f33ec6e8 --- /dev/null +++ b/packages/react-strict-animated/src/web/__tests__/SpringAnimation-test.js @@ -0,0 +1,30 @@ +/** + * 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 + */ + +import SpringAnimation from '../animations/SpringAnimation'; + +describe('SpringAnimation (web)', () => { + test('rejects a non-positive stiffness value', () => { + expect( + () => new SpringAnimation({ toValue: 1, stiffness: 0, damping: 10, mass: 1 }) + ).toThrow('Stiffness value must be greater than 0'); + }); + + test('rejects a non-positive damping value', () => { + expect( + () => new SpringAnimation({ toValue: 1, stiffness: 100, damping: 0, mass: 1 }) + ).toThrow('Damping value must be greater than 0'); + }); + + test('rejects a non-positive mass value', () => { + expect( + () => new SpringAnimation({ toValue: 1, stiffness: 100, damping: 10, mass: 0 }) + ).toThrow('Mass value must be greater than 0'); + }); +}); diff --git a/packages/react-strict-animated/src/web/animations/SpringAnimation.js b/packages/react-strict-animated/src/web/animations/SpringAnimation.js index 37ecf8b7..0eb39d1c 100644 --- a/packages/react-strict-animated/src/web/animations/SpringAnimation.js +++ b/packages/react-strict-animated/src/web/animations/SpringAnimation.js @@ -109,7 +109,7 @@ export default class SpringAnimation implements AnimatedAnimation { throw new Error('Damping value must be greater than 0'); } if (this.#mass <= 0) { - throw new Error('Damping value must be greater than 0'); + throw new Error('Mass value must be greater than 0'); } }