Add unit test with mock function#33
Conversation
gemtechd
left a comment
There was a problem hiding this comment.
use the it test function and not test
see more comments about the code
| constructor({ point1 = new Point(), point2 = new Point(), n = undefined, slope = undefined }) { | ||
| if (!(point1 instanceof Point) || !(point2 instanceof Point)) { | ||
| throw new Error('InvalidPointError: point1 and point2 must be instances of Point'); | ||
| } |
There was a problem hiding this comment.
what happens if n is a string, or if slope is an object (for example)
modules/ecs6-class/line.js
Outdated
| } | ||
|
|
||
| calculateSlope() { | ||
| calculateSlope = () => { |
There was a problem hiding this comment.
it's better it should be calculateSlope() and not calculateScope = () =>
| this.calculateNOfLineFunction(); | ||
| } | ||
| if (this.slope === 0) { | ||
| throw new Error('InvalidSlopeError: Slope cannot be zero for calculating X by Y'); |
There was a problem hiding this comment.
so what is the x? how do you calculate it?
| const Point = require('../modules/ecs6-class/point'); | ||
| const calculateDistance = (point1, point2) => { | ||
| if (!point1 || !point2 || typeof point1.x !== 'number' || typeof point1.y !== 'number' || typeof point2.x !== 'number' || typeof point2.y !== 'number') { | ||
| throw new Error('Invalid input points'); |
There was a problem hiding this comment.
which input is invalid? and why is it invalid?
modules/geometry-calculation.js
Outdated
| const calculateJunctionPoint = (line1, line2) => { | ||
|
|
||
| if (!(line1 instanceof Line) || !(line2 instanceof Line)) { | ||
| throw new Error('Invalid input lines'); |
|
|
||
| describe('Line class', () => { | ||
| test('should create a line with default points and undefined slope and n', () => { | ||
| const line = new Line({}); |
There was a problem hiding this comment.
give more examples for the good constructor
tests/ecs6-class/line.test.js
Outdated
|
|
||
|
|
||
| test('should handle horizontal lines correctly by throwing an error', () => { | ||
| // Create a horizontal line (slope = 0) |
|
|
||
| describe('Point class', () => { | ||
| test('should create a point with default values (0, 0)', () => { | ||
| const point = new Point(); |
There was a problem hiding this comment.
Where are the mocks for the functions?
tests/geometry_calculation.test.js
Outdated
| const line = new Line({ point1: point1, point2: point2} ); | ||
| const point = new Point({ x: 2, y: 2 }); | ||
| line.calculateSlope(); | ||
| line.calculateNOfLineFunction(); |
There was a problem hiding this comment.
you can't call different functions so that you test will be good
each unittest calls only one function (that's what you have written in the presentation)
No description provided.