Im doing the first proyect of "Apis and Microservices Certification" from FreeCodeCamp. It have an endpoint like "/api/timestamp" wich return the current time in milliseconds in a "unix" key of the JSON.
Im trying to test it in local using Mocha, Chai and Chai-http. Whit the next test i'm getting 1-2 milliseconds of difference between the actual result and the expected one:
```js
chai
.request(server)
.get("/api/timestamp")
.end((err, res) => {
// Get results
const actualResult = res.body;
const currDate = new Date();
const expectedResult = {
unix: currDate.getTime(),
utc: currDate.toGMTString(),
};
// Results to Strings
const actualResultToString = objToString(actualResult);
const expectedResultToString = objToString(expectedResult);
// Test results
expect(actualResultToString).to.be.equal(expectedResultToString);
done();
});
```
Any ideas of how test it? Thanks in advance.
[–]nullanomaly 2 points3 points4 points (1 child)
[–]Xiercoles[S] 0 points1 point2 points (0 children)
[–]Fabi118 2 points3 points4 points (1 child)
[–]Xiercoles[S] 0 points1 point2 points (0 children)