Skip to content

Commit 493673f

Browse files
[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).
1 parent bbe0ece commit 493673f

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
*/
9+
10+
import SpringAnimation from '../animations/SpringAnimation';
11+
12+
describe('SpringAnimation (web)', () => {
13+
test('rejects a non-positive stiffness value', () => {
14+
expect(
15+
() => new SpringAnimation({ toValue: 1, stiffness: 0, damping: 10, mass: 1 })
16+
).toThrow('Stiffness value must be greater than 0');
17+
});
18+
19+
test('rejects a non-positive damping value', () => {
20+
expect(
21+
() => new SpringAnimation({ toValue: 1, stiffness: 100, damping: 0, mass: 1 })
22+
).toThrow('Damping value must be greater than 0');
23+
});
24+
25+
test('rejects a non-positive mass value', () => {
26+
expect(
27+
() => new SpringAnimation({ toValue: 1, stiffness: 100, damping: 10, mass: 0 })
28+
).toThrow('Mass value must be greater than 0');
29+
});
30+
});

packages/react-strict-animated/src/web/animations/SpringAnimation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default class SpringAnimation implements AnimatedAnimation {
109109
throw new Error('Damping value must be greater than 0');
110110
}
111111
if (this.#mass <= 0) {
112-
throw new Error('Damping value must be greater than 0');
112+
throw new Error('Mass value must be greater than 0');
113113
}
114114
}
115115

0 commit comments

Comments
 (0)