MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / test_fetch_post_json

Function test_fetch_post_json

apps/automated/src/fetch/fetch-tests.ts:183–200  ·  view source on GitHub ↗
(done)

Source from the content-addressed store, hash-verified

181};
182
183export var test_fetch_post_json = function (done) {
184 // >> fetch-post-json
185 fetch('https://http-echo.nativescript.org/post', {
186 method: 'POST',
187 headers: new Headers({ 'Content-Type': 'application/json' }),
188 body: JSON.stringify({ MyVariableOne: 'ValueOne', MyVariableTwo: 'ValueTwo' }),
189 })
190 .then((r) => r.json())
191 .then(function (r) {
192 // >> (hide)
193 TKUnit.assert(r.json['MyVariableOne'] === 'ValueOne' && r.json['MyVariableTwo'] === 'ValueTwo', 'Content not sent/received properly! Actual result is: ' + r.json);
194 done(null);
195 // << (hide)
196 // console.log(result);
197 })
198 .catch(failOnError(done));
199 // << fetch-post-json
200};
201
202const failOnError = function (done: (err: Error, res?: string) => void) {
203 return (e) => done(e);

Callers

nothing calls this directly

Calls 3

fetchFunction · 0.85
failOnErrorFunction · 0.85
assertMethod · 0.80

Tested by

no test coverage detected