Open lanphan opened 3 years ago
In addition, I'd like to get some data from external apis to automate some testing scenarios, do Unit testing support it?
well.. if you're asking me to put my leet-haxor hat on, you can do something like this
const http = require('http')
const google = await new Promise(resolve => {
http.get('http://google.com', resolve);
});
expect(google.readable).to.equal(true);
But I can't say I'd recommend it. Not sure of another way, though. We don't expose axios
(or any other dependency) to the test itself, from what I can tell.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I am also looking for a way to access variables in unit testing that I can access in the debug tab. Is there a way to do this?
I'm testing an API that needs to use generated values for some imputs since the backend of the service doesn't allow duplications of certain data in the database. But that makes it hard (read: impossible) to do any assertions on the data that I'm receiving in the responses.
+1 how to access and modify variables, request body and request query params in unit testing. Currently unit testing is not very useful because only one test is possible. No way to test multiple edge cases with different sets of data per request. Basically I need something like this:
@lanphan @sillen102 at the moment we don't expose this functionality and allow you to for example tinker with the environment variables, similar to what Postman allows programmatically in their Pre-Request and Test code in scripts.
@mugi-luffy what you mention is also not supported, but is catalogued as improvement here: https://github.com/Kong/insomnia/issues/4482
We are at the moment gathering all this kind of feedback to try and come up with a feasible plan to improve the test feature.
Feel free to report any other issues or improvements you notice 👍
@filfreire, do you have an ETA on this feature?
👍 +1
Just discovered insomnia couple hours ago and it feels like it knows exactly what I need and has that! The only exception so far ... accessing environment variables in unit tests. I need the test to have different expectations on different environments (seems quite natural). Any chance to get that? (Or would it be possible to write a plugin?)
👍 +1
Yeah, I will +1 this one as well.
Programmatically being able to access:
Is very useful in tests.
Why?
Environment variable access means I don't need to duplicate data between env vars and unit tests
const response1 = await insomnia.send();
const responseData = JSON.parse(response1.data);
expect(response1.valueOnResponse).to.equal(insomnia.environment.valueInEnvVars);
Information inside the request can be validated against the response data
const request = insomnia.currentRequest;
const requestData = JSON.parse(request .data);
const response1 = await insomnia.send();
const responseData = JSON.parse(response1.data);
expect(response1.valueX).to.equal(requestData valueX);
👍 +1
+1 !
+1
+1
+1 I think this feature is a must have. Thanks for the good work on insomnia by the way.
Im still not seeing a way to edit or change Envrionment Veriables in the Test tab. I have Variables that get submitted via the URL and I can not write tests to change that info Or multiple similar tests with Different info for those variables. #4482 did not solve the problem.
Also, Its seems a bit odd that the Test tab doesnt have a way to select an envronment.
Big +1 for this. Ideally we should be able to create one request with some part of it that varies. For example I'm testing a content search API where I want to parameterize the query text in unit tests to check the results.
I shouldn't have to create many different requests that are otherwise identical to do this. I should be able to change them in the unit test suite before launching each request.
+1
+1
+1
+1
+1
+1
What is your question? A clear and concise description of what you are wanting to ask. Ex. I'm always frustrated when [...] Environment variable and template tags are very powerful in Collections, but I don't find any document about their usage in Unit testing. Is it possible to use them in Unit testing? In addition, I'd like to get some data from external apis to automate some testing scenarios, do Unit testing support it?
What is the context? If applicable, describe the context in which you are asking the question. Ex. I am trying to do x with y [...] To support table-driven testing, I'd like to define a static list of data before executing tests. In some special cases, these data can be got from external apis which I'd like to call to get that data to use, therefore, I need to call external api in unit testing.