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

Bounds.overlaps unit tests & using a regex in the toThrow unit tests.

This commit is contained in:
gsenden 2024-05-20 12:50:07 +02:00
parent c2f27fba95
commit 11ade3cc96
4 changed files with 70 additions and 25 deletions

View file

@ -27,7 +27,7 @@ describe('Axes.fromVertices', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -72,7 +72,7 @@ describe('Axes.rotate', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});

View file

@ -68,7 +68,7 @@ describe('Bounds.update', () => {
const result = () => Bounds.update(bounds, vertices, velocity);
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
it('should not be able to update undefined bounds with valid vertices', () => {
@ -81,7 +81,7 @@ describe('Bounds.update', () => {
const result = () => Bounds.update(bounds, vertices, velocity);
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'min')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -120,7 +120,7 @@ describe('Bounds.contains', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'x')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
it('should not be able to determine that undefined bounds contains valid vector', () => {
@ -133,6 +133,51 @@ describe('Bounds.contains', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'min')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
describe('Bounds.overlaps', () => {
it('should be able to determine that bounds overlap with valid other bounds', () => {
// Arrange
const bounds = getTestBounds();
const otherBounds = getTestBounds();
otherBounds.max.x += 100.;
otherBounds.max.y += 100.;
// Act
const result = Bounds.overlaps(bounds, otherBounds);
// Assert
expect(result).toEqual(true);
});
it('should be able to determine that bounds do not overlap with valid other bounds', () => {
// Arrange
const bounds = getTestBounds();
const otherBounds = getTestBounds();
otherBounds.min.x = 1.;
otherBounds.min.y = 1.;
otherBounds.max.x = 10.;
otherBounds.max.y = 10.;
// Act
const result = Bounds.overlaps(bounds, otherBounds);
// Assert
expect(result).toEqual(false);
});
it('should not be able to determine that bounds overlap with undefined other bounds', () => {
// Arrange
const bounds = getTestBounds();
const otherBounds = undefined;
// Act
const result = () => Bounds.overlaps(bounds, otherBounds);
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});

View file

@ -52,7 +52,7 @@ describe("Vector.clone", () => {
}
// Assert
expect(result).toThrow("Cannot read properties of undefined (reading 'x')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -79,7 +79,7 @@ describe("Vector.magnitude", () => {
}
// Assert
expect(result).toThrow("Cannot read properties of undefined (reading 'x')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
})
});

View file

@ -77,7 +77,7 @@ describe('Vertices.create', () => {
const result = () => Vertices.create(points, body);
// Assert
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -168,7 +168,7 @@ describe('Vertices.fromPath', () => {
const result = () => Vertices.fromPath(path, body);
// Assert
expect(result).toThrow("Cannot read properties of undefined (reading 'replace')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -249,7 +249,7 @@ describe('Vertices.area', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -315,7 +315,7 @@ describe('Vertices.rotate', () => {
const result = () => Vertices.rotate(vertices, angle, point);
// Assert
expect(result).toThrow("Cannot read properties of undefined (reading 'x')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
@ -330,7 +330,7 @@ describe('Vertices.rotate', () => {
const result = () => Vertices.rotate(vertices, angle, point);
// Assert
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -357,7 +357,7 @@ describe('Vertices.centre', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -384,7 +384,7 @@ describe('Vertices.mean', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -442,7 +442,7 @@ describe('Vertices.inertia', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -493,7 +493,7 @@ describe('Vertices.translate', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'x')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
@ -508,7 +508,7 @@ describe('Vertices.translate', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -550,7 +550,7 @@ describe('Vertices.contains', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'x')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
@ -564,7 +564,7 @@ describe('Vertices.contains', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -652,7 +652,7 @@ describe('Vertices.scale', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -836,7 +836,7 @@ describe('Vertices.chamfer', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -872,7 +872,7 @@ describe('Vertices.clockwiseSort', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -902,7 +902,7 @@ describe('Vertices.hull', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'slice')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});
@ -949,7 +949,7 @@ describe('Vertices.isConvex', () => {
// Assert
// TODO: This causes a read from undefined. This should probably be fixed.
expect(result).toThrow("Cannot read properties of undefined (reading 'length')");
expect(result).toThrow(/^Cannot read properties of undefined \(reading '.*'\)$/);
});
});