I'm new to Svelte and learning it for self-education.
I'm trying to implement very basic scenario:
there are multiple buttons on the page, each button fetches some data and displays result in the same area.
To make sure that due to the different network response timings later result will not be overwritten by old request I want to abort all previous fetches.
Here is the REPL I've made so far: https://svelte.dev/repl/c763e1814da740f186620d75ad1fa42f?version=3.38.2
Question: why request aborted in advance and how to correct this?
(Any advises how to make my Svelte code styling better will be much appreciated, I suspect this logic can be implemented in much better/efficient way)
It's the AbortController. Once abort() is called it stays in the aborted state. I looked for some references but couldn't find any documentation that states this explicitly. However, a bit of trial and error seems to prove this. You need to create a new AbortController after calling abort().
Related
I am trying to pass the result of promise fetch from a child to parent component with emit. Emit works perfectly fine before the $fetch where my parent component was able to receive it, however the emit does not work in the image as seen where it is used after $fetch.
I have been trying to solve it for hours but have zero idea on why does it not work. Am learning, so do enlighten me if anyone knows the reason for it.
Thank you very much, appreciative of your help and time.
Cheers.
I tried to emit after fetch to API and expected my parent component to receive the event but it did not.
Are you using the fetch() hook that comes with Nuxt? If so, it should be called outside your methods block and without the '$'. Review the Nuxt Docs on data fetching. You may also want to consider using the 'asyncData' hook depending on your use case.
Also, should it be a DELETE method instead? I don't know your API, but I assume a function called "remove" should perform a delete operation and not PUT.
This question already has answers here:
Dynamic scenario freezes when called using afterFeature hook
(2 answers)
Closed 1 year ago.
I want a common implementation to write the: request-body, request-method & response-body to an output file for all the HTTP requests that I make in any of the karate feature files.
I have read through the documentation, and the closest option that I found was the afterScenario hook. However this doesn't help me in cases where I want to make multiple API calls in the same scenario.
I also tried using karate.prevRequest object by passing it to java function that I wrote. While this helps me capture the information that I want, I have to keep calling my java function after every API call, which I don't want to do.
I want to be able to write a hook that gets called after every API call and gives me access to request-body, request-headers, response-headers, response-body, request-method and request URL.
This should be fairly straight forward, clearly I seem to be missing something here.
First, I personally think that this is a mis-use of Karate, and you seem to be more interested in reports than actually doing testing. Take some time to think about it. Karate has excellent report integration and you are just wasting your time doing this in my very honest, sincere opinion. No one has asked for this.
Anyway. There is a new ExecutionHook in 0.9.5.RC4, details here: https://github.com/intuit/karate/issues/970#issuecomment-557443551
You can implement afterStep, see if it is a method step and then do this. If you need changes, open an issue. Also see: https://stackoverflow.com/a/60944060/143475
EDIT: just remembered - in the develop branch we added a way to intercept all requests and responses: https://twitter.com/karatedsl/status/1195240779213496320 - will be happy to get your feedback and see if we can merge this concept with the above hook - or improve the interfaces if needed
EDIT: in many cases, the afterScenario may be sufficient, note that you can call any Karate feature, which means you can do HTTP requests: https://stackoverflow.com/a/51467470/143475
EDIT - the hooks API has changed for 1.0: https://github.com/intuit/karate/wiki/1.0-upgrade-guide
The ExecutionHook supports quite a lot different use cases.
Steps can be aborted or changed
Request and Response can be sniffed
See ExecutionHookExampleTest on how to use an ExecutionHook.
The API has changed. With karate version 1.1.0 (correct me, if I'm wrong)
It's now com.intuit.karate.RuntimeHook and you can use
com.intuit.karate.Runner.Builder#hook or
com.intuit.karate.Runner.Builder#hooks
method to add a hook to your karate test case execution.
I'm using jasmine-node to test my API, and it has worked great for my GET routes. Now, however, I need to test some POSTs and I'm not sure how to go about this without changing my database.
One thought I had was to reset whatever value I change at the end of each spec.
Is this reasonable or is there a better way to go about testing POST requests to my API?
Wrap anything that modifies your database into a transaction. You can have your database changes and then rollback after each test.
usually you are supposed to have a test database, so modify that one is not a big issue. also, a general approach would be not to rely on predefined values on the database (i.e, the GET always request the SAME object..) but try with different objects each time. (using predefined objects may hide problems when the data is slighty different..).
in order to implement the second strategy, you can execute a test with a POST with pseudo-random data to create a new object, and use the returned ID to feed the following GET, UPDATE and finally the DELETE tests.
Just make a duplicate processing page/function and send the data to that for debugging. Comment out anything that makes changes to the database.
Alternatively, pass a variable in your call such as "debug" and have an if/else section in your original function for debugging, ignoring the rest of the function.
Another alternative still is to duplicate your database table and name it debug table. It will have the same structure as your original. Send the test data to it instead and it won't change your original database tables.
I'm pretty sure that you've come up with some solution for your problem already.
BUT, if you don't, the Angular $httpBackend will solve your problem. It is a
Fake HTTP backend implementation suitable for unit testing applications that use the $http service.
I'm trying to find a way to cancel BreezeJS queries for the purpose of implementing a live search that queries BreezeJS on keypress (see my other question).
I know that in Angular, $http requests can be cancelled by passing a promise to the timeout parameter in the config object, and then calling resolve() on that promise.
I also know that I can get BreezeJS to use my module's $http insance with:
var ajax = breeze.config.initializeAdapterInstance('ajax', 'angular');
ajax.setHttp($http);
So I was thinking about possibly creating a request interceptor on $http that would set config.timeout to a promise. But that still leaves me quite a few steps away from solving the problem, because I would somehow need to be able to give the promise to my interceptor from the code running the query (so that the querying code could resolve() the promise if needed).
Is there a better way? Is it even possible?
Update 16 May 2014
You can set HTTP-level timeout and cancellation with the AJAX Adapter's requestInterceptor as of v.1.4.12. See the documentation, "Controlling AJAX calls".
Original answer
The EntityManager HTTP service operations don't offer cancel or timeout options. Maybe they will someday.
The v.1.4.11 Breeze AJAX adapters don't offer cancel or timeout options either. But they will in v.1.4.12 and you can see the preview on github right now.
The samples on github illustrate both cancel and timeout with the new adapters. For users of the jQuery AJAX component there is DocCode:jQueryAjaxAdapterTests.js. For users of Angular's $http there is the Zza-Node-Mongo:ajax-adapter.async.spec.js.
It's best if you can run the samples but if you can't (perhaps because you don't use one of the technologies involved), the test files (see links above) are easy to read and you should glean the ideas that will help. At least I hope so.
Usage
Cancel and timeout are useful features. Do you need them for your use case? Maybe. But you'd want to take a first step of de-bouncing the text that users enter into your "live search" so that you aren't firing off 100s of pointless queries.
That observation is discussed in your related StackOverflow question.
I have a function which makes a post request to my server when a button is clicked, however I notice in the console log that a single request is being sent to that resource when when it shouldn't have been triggered and I don't know why.
It is seemingly triggered a short time after another function is called which makes a get request to another resource, however that function is fairly simple; I've looked through it on and off for the past couple days and am at a loss and so have just been ignoring it mostly.
It's not really causing interference in the program, it just throws an exception on the server and the request fails which has no reprocussions to the client either, but obviously I don't want that in production and it's bothering me because I just can't figure it out. I really cannot imagine it's being triggered there and it's also strange because it happens some amount of time after that call, not right after as you'd think if it were called by it directly. So anyway, short of stepping through my whole program is there any way to determine what called a function? I'd think it would be a fairly common feature, but I just can't seem to find it if so.
You can use console.trace() in the code, or you can't edit the code?
Some codes for tracing (each line have such tracing styles on Console):
console.log(object[, object, ...])
console.debug(object[, object, ...])
console.info(object[, object, ...])
console.warn(object[, object, ...])
console.error(object[, object, ...])
....
The official documentation about that (if you use Firebug):
https://getfirebug.com/wiki/index.php/Console_API