Files
bruno/packages/bruno-tests/collection/scripting/inbuilt modules/node-fetch/node-fetch-pre-req-script.bru
lohit 126c648d7d wip: code cleanup, added axios shim to quick js vm (#2851)
* wip: code cleanup, added axios, nanoid shims for quickjs vm
* wip: test fn fix
* wip: scrip exec fix
* wip: added node-fetch & uuid shims
2024-08-19 10:30:19 +05:30

37 lines
642 B
Plaintext

meta {
name: node-fetch-pre-req-script
type: http
seq: 1
}
get {
url: {{host}}/ping
body: none
auth: none
}
script:pre-request {
const fetch = require("node-fetch");
const url = "https://testbench-sanity.usebruno.com/api/echo/json";
const response = await fetch(url, {
method: 'post',
body: JSON.stringify({hello:'bruno'}),
headers: {'Content-Type': 'application/json'}
});
req.setBody(response.data);
req.setMethod("POST");
req.setUrl(url);
}
tests {
test("req.getBody()", function() {
const data = res.getBody();
expect(data).to.eql({
"hello": "bruno"
});
});
}