Skip to content

Commit

Permalink
fix code styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Reverier-Xu committed Apr 23, 2024
1 parent c09ed08 commit a022cf6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/core/Ky.ts
Expand Up @@ -203,7 +203,7 @@ export class Ky {
}

if (this._options.json !== undefined) {
this._options.body = this._options.stringifyJson ? this._options.stringifyJson(this._options.json) : JSON.stringify(this._options.json);
this._options.body = this._options.stringifyJson?.(this._options.json) ?? JSON.stringify(this._options.json);
this.request.headers.set('content-type', this._options.headers.get('content-type') ?? 'application/json');
this.request = new globalThis.Request(this.request, {body: this._options.body});
}
Expand Down
8 changes: 5 additions & 3 deletions test/main.ts
Expand Up @@ -736,14 +736,16 @@ test('parseJson option with promise.json() shortcut', async t => {

test('stringifyJson option with request.json()', async t => {
const server = await createHttpTestServer({bodyParser: false});

Check failure on line 739 in test/main.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Trailing spaces not allowed.
const json = {hello: 'world'};
const result = {data: json, extra: 'extraValue'};

server.post('/', async (request, response) => {
const body = await parseRawBody(request);
t.is(body, '{"data":{"hello":"world"},"extra":"extraValue"}');
t.is(body, JSON.stringify(result));
response.end();
});

const json = {hello: 'world'};

await ky.post(server.url, {
stringifyJson: data => JSON.stringify({
data,
Expand Down

0 comments on commit a022cf6

Please sign in to comment.