0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-03-14 00:38:41 -04:00

Body.setAngularVelocity unit tests

This commit is contained in:
gsenden 2024-05-31 20:45:51 +02:00
parent 00be09c78c
commit 48c9a89bad

View file

@ -1652,6 +1652,52 @@ describe('Body.setSpeed', () => {
// Act
let result = () => Body.setSpeed(body, speed);
// Assert
// TODO: This causes a read or set from undefined. This should probably be fixed.
expect(result).toThrow(/^Cannot .* properties of undefined \(.* '.*'\)$/);
});
});
describe('Body.setAngularVelocity', () => {
it('should be able to set the angular velocity on a body', () => {
// Arrange
const body = getTestBodyWithPartsWithParent();
const velocity = 37.;
// Act
Body.setAngularVelocity(body, velocity);
// Assert
assertFloat(body.angle, 101.);
assertFloat(body.anglePrev, -176.49999999999994);
assertFloat(body.angularVelocity, 37.);
assertFloat(body.angularSpeed, 37.);
});
it('should not be able to set an angular velocity on a body with an undefined velocity', () => {
// Arrange
const body = getTestBodyWithPartsWithParent();
const velocity = undefined;
// Act
Body.setAngularVelocity(body, velocity);
// Assert
// TODO: This causes the result to have undefined and NaN properties. This should probably be fixed.
assertFloat(body.angle, 101.);
expect(body.anglePrev).toEqual(NaN);
expect(body.angularSpeed).toEqual(NaN);
expect(body.angularVelocity).toEqual(NaN);
});
it('should not be able to set the angular velocity on an undefined body', () => {
// Arrange
const body = undefined;
const velocity = 37.;
// Act
let result = () => Body.setAngularVelocity(body, velocity);
// Assert
// TODO: This causes a read or set from undefined. This should probably be fixed.
expect(result).toThrow(/^Cannot .* properties of undefined \(.* '.*'\)$/);