-
Notifications
You must be signed in to change notification settings - Fork 41
Add unit test with mock function #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
gemtechd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which one?
|
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comments before pushing
|
|
||
| describe('Point class', () => { | ||
| test('should create a point with default values (0, 0)', () => { | ||
| const point = new Point(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create more examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.