mirror of
https://github.com/liabru/matter-js.git
synced 2025-03-14 00:38:41 -04:00
Body.setCentre unit tests
This commit is contained in:
parent
e1a72724b6
commit
c83dba344b
1 changed files with 72 additions and 0 deletions
|
@ -1029,4 +1029,76 @@ describe('Body.setParts', () => {
|
|||
// TODO: This causes a read or set from undefined. This should probably be fixed.
|
||||
expect(result).toThrow(/^Cannot .* properties of undefined \(.* '.*'\)$/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Body.setCentre', () => {
|
||||
it('should be able to set the centre on a default body, not relative', () => {
|
||||
// Arrange
|
||||
const body = getTestBodyWithPartsWithParent();
|
||||
const centre = { x: 42., y: 43. };
|
||||
const relative = false;
|
||||
|
||||
// Act
|
||||
Body.setCentre(body, centre, relative);
|
||||
|
||||
// Assert
|
||||
assertXY(body.position, 42., 43.);
|
||||
assertXY(body.positionPrev, 46., 47.);
|
||||
});
|
||||
|
||||
it('should be able to set the centre on a default body, with undefined relative', () => {
|
||||
// Arrange
|
||||
const body = getTestBodyWithPartsWithParent();
|
||||
const centre = { x: 42., y: 43. };
|
||||
const relative = undefined;
|
||||
|
||||
// Act
|
||||
Body.setCentre(body, centre, relative);
|
||||
|
||||
// Assert
|
||||
assertXY(body.position, 42., 43.);
|
||||
assertXY(body.positionPrev, 46., 47.);
|
||||
});
|
||||
|
||||
it('should be able to set the centre on a default body, relative', () => {
|
||||
// Arrange
|
||||
const body = getTestBodyWithPartsWithParent();
|
||||
const centre = { x: 42., y: 43. };
|
||||
const relative = true;
|
||||
|
||||
// Act
|
||||
Body.setCentre(body, centre, relative);
|
||||
|
||||
// Assert
|
||||
assertXY(body.position, 181., 183.);
|
||||
assertXY(body.positionPrev, 185., 187.);
|
||||
});
|
||||
|
||||
it('should not be able to set an undefined centre on a default body, not relative', () => {
|
||||
// Arrange
|
||||
const body = getTestBodyWithPartsWithParent();
|
||||
const centre = undefined;
|
||||
const relative = false;
|
||||
|
||||
// Act
|
||||
let result = () => Body.setCentre(body, centre, relative);
|
||||
|
||||
// Assert
|
||||
// TODO: This causes a read or set from undefined. This should probably be fixed.
|
||||
expect(result).toThrow(/^Cannot .* properties of undefined \(.* '.*'\)$/);
|
||||
});
|
||||
|
||||
it('should not be able to set the centre on an undefined body, not relative', () => {
|
||||
// Arrange
|
||||
const body = undefined;
|
||||
const centre = { x: 42., y: 43. };
|
||||
const relative = false;
|
||||
|
||||
// Act
|
||||
let result = () => Body.setCentre(body, centre, relative);
|
||||
|
||||
// Assert
|
||||
// TODO: This causes a read or set from undefined. This should probably be fixed.
|
||||
expect(result).toThrow(/^Cannot .* properties of undefined \(.* '.*'\)$/);
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue