I'm doing true TDD here. But it's way different when you do that in JS as compared to a language such as C#.
I plan on using Koa.js. So I started a new test class that has my first test with some pseudo code in how I want to start writing my test.
This is obviously not correct JS and I'm working to figure out how that's gonna be done as I go too with objects, etc. so this is very very pseudo and want help understanding how to make this real with Koa in mind.
test('can return one car', function (){
var expectedCar = {
"cars": [{}]
};
var response = someService.Get("/Cars");
assert.equal(expectedCar, response.Cars[0]);
});
This test should require me to start creating Koa.js endpoints. I just don't know how I'll go about this yet...hence posting here for help.
Right now I have a server.js as so and really that first TDD test should have forced me to create this server.js with this code for initial code structure to start out with:
'use strict';
module.exports = koa = require('koa')();
let app = koa;
app.listen(function(){
console.log('Koa app is listening on port ');
});
Ok so I have this, it runs ok as in I get an app listening on the port.
I just don't know how my test code should look as in viewing from traditional lets say C# I'd wanna create a CarService.cs. Well this isn't C#. This is JS. This is Koa.js and node.
Now lets review the goals of my first test:
- I want to call and endpoint (that doesn't yet exist but forces me to create it..probably a Koa.js route in index.js)
- I want to verify that the endpoint (app.get) method did give me a response with an instance of a car in the object I send back in the response. As you can see from my pseodo, that instance doesn't have to have any properties yet, I just wanna be sure I get an instance of car period...minimal code to make this test pass
- So my assert should assert that expetedCar is the same as the response.Cars[0] car I send back
I just don't know how to do this with JS/Koa/Node.js in this scenario. I don't understand what my variables would look like in my TDD test that would require me to go create that stuff.
In C#, it's simple, you just do stuff like this:
[Test]
CanGetOneCar()
{
var service = new CarService();
var requestParams = new requestParams[]{'a','b','c'};
var response = service.Get(requestParams);
Assert.AreSame(new CarService(){}, response.Cars[0]);
}
so in C# the response object would have a Cars array with an instance of a Car with no properties yet. That's what I expect to assert against in my first test.
How the hell would I do this in JS, Node, Koa, a whole different ballgame? How would I form my test in this case?
And remember I'm using SuperTest for integration testing, those are for my BDD tests, it shouldn't be used for my TDD. My TDD should be testing the CODE at the koa service layer such as testing the route methods, etc., not integration testing with real requests. I want to TDD the app.get() methods for example.
Aucun commentaire:
Enregistrer un commentaire