Hi Andreas,

> Why one level lower here?
That level difference is often the difference between a root node and an enclosing document-node.
The send-request()[2] is returning a document-node. You can mock the same as below.

/Andy

declare function local:httpMockResponse()
{
    <http:response status="200"/>,

    document{
      <html>
      <foo>bar</foo>
    </html>
   }
};


On Fri, 13 Mar 2026 at 11:31, Andreas Hengsbach | nexoma via BaseX-Talk <basex-talk@mailman.uni-konstanz.de> wrote:
Hello everybody,

I'm currently trying to mock the HTTP client's response for unit tests.
In both cases, I have a sequence, but I need to handle them differently.

Why is that, and how can I correctly mock a response so that it behaves exactly like the real response?

Here's my test script:

# schnipp
declare function local:httpMockResponse() {
  (
    <http:response status="200"/>,
    <html>
      <foo>bar</foo>
    </html>
  )
};
<real>{http:send-request((),"https://nexoma.de")[2]/html/name()}</real>,
<mock>{local:httpMockResponse()[2]/html/name()}</mock>,

<mock2>{local:httpMockResponse()[2]/name()}</mock2> (: Why one level lower here? :)
# schnapp

I just don't get it. :(

Best regards
Andreas