Advanced GraphQL Integration Test with Jest
This course has been updated! We now recommend you take the Advanced GraphQL, v2 course.
Transcript from the "Integration Test with Jest" Lesson
>> Scott Moss: So that's unit testing. And as far as doing integration test, we're gonna use this run function that I was talking about, which is here. So basically, take a query and some variables, and then we're gonna execute it and see what comes back. So let's do that, this one's gonna be fun.
[00:00:18] So let's set up some tasks in a database. I'm just gonna just take this same thing here, do it again. So let's set these task up.
>> Scott Moss: And they get cleared every time, so we're good. And then, I'm gonna make a query.
>> Scott Moss: I'm gonna do the same query, the same resolver.
[00:00:36] I'm actually gonna run it through the query instead of running the resolver. So let's do query, and it's just going to be a string here. Using the template string. And we're just gonna make a simple query. Actually, let's do a name query here, just so we can use variables.
>> Scott Moss: We'll call it task. And then task.graphic EO takes as an argument. Input, with a task input, which is a project ID at minimum. So let us do that. So task takes an input. Which is a task input.
>> Scott Moss: And we task which
>> Scott Moss: Input. Referencing that input.
[00:01:23] And then, we're just gonna get the ID and name. So we got that. And then, for the variables
>> Scott Moss: It's gonna be, input.
>> Scott Moss: Or maybe not input, yeah, I think it's just that. Put project.
>> Scott Moss: And that's the only one we really need. So we got the project, and now we can actually run this query.
[00:01:48] So we need to do is need to, we already got run query there. We'll get the results.
>> Scott Moss: Gonna wait it, cuz it's async. Pass in the query.
>> Scott Moss: Pass in the variables. Get the results. And then, this is gonna be a raw graph kill, so we wanna expect results.errors to be undefined.
[00:02:20] And let's just start with there and see what breaks.
>> Scott Moss: Cool, so far so good, looks like it's running. So then, now we expect,
>> Scott Moss: Or did it run this one?
>> Speaker 2: I think to be undefined is a function, right?
>> Scott Moss: Yeah, I think so. Yeah, that was a false positive.
>> Scott Moss: There we go, okay. So this ones says variable input of required type task of. Okay, I think I do need to put an input here, something like that. There we go.
>> Scott Moss: There we go. Okay, so now, it's working. So now, we know it's not erroring out, we do need to test that the results are indeed what we want.
[00:03:08] So we should expect results.data, cuz that's the data property on GraphQL. Now, let's do a simple length property. To have length of 2 task, cuz we put 2 here. And you should definitely write more detailed tasks than just checking the length. And this one says have a length property that is a number received.
>> Scott Moss: Okay, cuz it's data.task.
>> Scott Moss: There we go.
>> Scott Moss: And that passes. So that was the integration test. Before that, that was a unit test