[{"data":1,"prerenderedAt":529},["ShallowReactive",2],{"page:\u002Fextensions\u002Fericlm\u002Fkubb-plugin-playwright\u002Fguides\u002Fnative-options-and-responses":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":528,"source":4},"extensions\u002Fericlm\u002Fkubb-plugin-playwright\u002Fguides\u002Fnative-options-and-responses.md",{},"Native options and responses",{"type":8,"value":9,"toc":521},"minimark",[10,14,19,61,248,254,292,299,303,327,497,511],[11,12,13],"p",{},"Pass Playwright fetch options through a generated helper and read the native response it returns.",[15,16,18],"h2",{"id":17},"pass-native-options","Pass native options",[11,20,21,22,26,27,30,31,36,37,40,41,40,44,40,47,40,50,40,53,56,57,60],{},"Every helper accepts an optional ",[23,24,25],"code",{},"options"," object typed as ",[23,28,29],{},"Omit\u003CNonNullable\u003CParameters\u003CAPIRequestContext['fetch']>[1]>, 'method'>",". It takes the native ",[32,33,35],"a",{"href":34},"https:\u002F\u002Fplaywright.dev\u002Fdocs\u002Fapi\u002Fclass-apirequestcontext#api-request-context-fetch","fetch options"," such as ",[23,38,39],{},"timeout",", ",[23,42,43],{},"failOnStatusCode",[23,45,46],{},"params",[23,48,49],{},"headers",[23,51,52],{},"data",[23,54,55],{},"form",", and ",[23,58,59],{},"multipart",".",[62,63,68],"pre",{"language":64,"filename":65,"code":66,"class":67},"typescript","options.spec.ts","import { test } from '@playwright\u002Ftest'\nimport { pwGetPetById } from '.\u002Fsrc\u002Fgen\u002Fplaywright'\n\ntest('waits longer for a slow endpoint', async ({ request }) => {\n  await pwGetPetById({\n    request,\n    path: { petId: '123' },\n    options: { timeout: 10_000, headers: { authorization: 'Bearer token' } },\n  })\n})","highlights",[23,69,71,98,99,98,115,98,117,98,149,98,163,98,174,98,199,98,237,98,244],{"class":70},"language-typescript",[72,73,76,80,84,88,91,94],"span",{"class":74,"style":75},"line","display: inline",[72,77,79],{"style":78},"color:#d73a49;--hls-dark:#f97583","import ",[72,81,83],{"style":82},"color:#005cc5;--hls-dark:#79b8ff","{ ",[72,85,87],{"style":86},"color:#24292e;--hls-dark:#e1e4e8","test ",[72,89,90],{"style":82},"} ",[72,92,93],{"style":78},"from ",[72,95,97],{"style":96},"color:#032f62;--hls-dark:#9ecbff","'@playwright\u002Ftest'","\n",[72,100,101,103,105,108,110,112],{"class":74,"style":75},[72,102,79],{"style":78},[72,104,83],{"style":82},[72,106,107],{"style":86},"pwGetPetById ",[72,109,90],{"style":82},[72,111,93],{"style":78},[72,113,114],{"style":96},"'.\u002Fsrc\u002Fgen\u002Fplaywright'",[72,116],{"class":74,"style":75},[72,118,119,123,126,129,131,134,137,140,143,146],{"class":74,"style":75},[72,120,122],{"style":121},"color:#6f42c1;--hls-dark:#b392f0","test",[72,124,125],{"style":82},"(",[72,127,128],{"style":96},"'waits longer for a slow endpoint'",[72,130,40],{"style":78},[72,132,133],{"style":78},"async ",[72,135,136],{"style":82},"({ ",[72,138,139],{"style":86},"request ",[72,141,142],{"style":82},"}) ",[72,144,145],{"style":78},"=> ",[72,147,148],{"style":82},"{",[72,150,151,154,157,160],{"class":74,"style":75},[72,152,153],{"style":82},"  ",[72,155,156],{"style":78},"await ",[72,158,159],{"style":121},"pwGetPetById",[72,161,162],{"style":82},"({",[72,164,165,168,171],{"class":74,"style":75},[72,166,167],{"style":82},"    ",[72,169,170],{"style":86},"request",[72,172,173],{"style":78},",",[72,175,176,178,181,184,186,189,191,194,197],{"class":74,"style":75},[72,177,167],{"style":78},[72,179,180],{"style":82},"path",[72,182,183],{"style":78},": ",[72,185,83],{"style":82},[72,187,188],{"style":82},"petId",[72,190,183],{"style":78},[72,192,193],{"style":96},"'123' ",[72,195,196],{"style":82},"}",[72,198,173],{"style":78},[72,200,201,203,205,207,209,211,213,216,218,220,222,224,227,229,232,235],{"class":74,"style":75},[72,202,167],{"style":78},[72,204,25],{"style":82},[72,206,183],{"style":78},[72,208,83],{"style":82},[72,210,39],{"style":82},[72,212,183],{"style":78},[72,214,215],{"style":82},"10_000",[72,217,40],{"style":78},[72,219,49],{"style":82},[72,221,183],{"style":78},[72,223,83],{"style":82},[72,225,226],{"style":82},"authorization",[72,228,183],{"style":78},[72,230,231],{"style":96},"'Bearer token' ",[72,233,234],{"style":82},"} }",[72,236,173],{"style":78},[72,238,239,241],{"class":74,"style":75},[72,240,153],{"style":78},[72,242,243],{"style":82},"})",[72,245,246],{"class":74,"style":75},[72,247,243],{"style":82},[11,249,250,251,253],{},"Helpers spread ",[23,252,25],{}," after the generated values:",[255,256,257,268,275,286],"ul",{},[258,259,260,263,264,267],"li",{},[23,261,262],{},"options.params"," replaces the generated query, and ",[23,265,266],{},"options.headers"," replaces the generated headers.",[258,269,270,271,274],{},"An explicit ",[23,272,273],{},"undefined"," also replaces a generated value.",[258,276,277,278,281,282,285],{},"Values such as ",[23,279,280],{},"timeout: 0"," and ",[23,283,284],{},"failOnStatusCode: false"," pass through unchanged.",[258,287,288,289,291],{},"Required OpenAPI groups stay required even when ",[23,290,25],{}," replaces their values.",[11,293,294,295,298],{},"The operation sets the HTTP method after the spread. TypeScript rejects ",[23,296,297],{},"options.method",", and passing it from JavaScript does not change the method.",[15,300,302],{"id":301},"read-the-response","Read the response",[11,304,305,306,309,310,40,313,40,316,40,319,322,323,326],{},"Helpers return the Playwright ",[23,307,308],{},"APIResponse"," without reading the body. Call ",[23,311,312],{},"status()",[23,314,315],{},"headers()",[23,317,318],{},"ok()",[23,320,321],{},"json()",", or ",[23,324,325],{},"text()"," as needed.",[62,328,331],{"language":64,"filename":329,"code":330,"class":67},"response.spec.ts","import { expect, test } from '@playwright\u002Ftest'\nimport { pwGetPetById } from '.\u002Fsrc\u002Fgen\u002Fplaywright'\n\ntest('handles a missing pet', async ({ request }) => {\n  const response = await pwGetPetById({ request, path: { petId: 'missing' } })\n  expect(response.status()).toBe(404)\n  expect(await response.text()).toContain('not found')\n})",[23,332,333,98,352,98,366,98,368,98,391,98,430,98,462,98,493],{"class":70},[72,334,335,337,339,342,344,346,348,350],{"class":74,"style":75},[72,336,79],{"style":78},[72,338,83],{"style":82},[72,340,341],{"style":86},"expect",[72,343,40],{"style":78},[72,345,87],{"style":86},[72,347,90],{"style":82},[72,349,93],{"style":78},[72,351,97],{"style":96},[72,353,354,356,358,360,362,364],{"class":74,"style":75},[72,355,79],{"style":78},[72,357,83],{"style":82},[72,359,107],{"style":86},[72,361,90],{"style":82},[72,363,93],{"style":78},[72,365,114],{"style":96},[72,367],{"class":74,"style":75},[72,369,370,372,374,377,379,381,383,385,387,389],{"class":74,"style":75},[72,371,122],{"style":121},[72,373,125],{"style":82},[72,375,376],{"style":96},"'handles a missing pet'",[72,378,40],{"style":78},[72,380,133],{"style":78},[72,382,136],{"style":82},[72,384,139],{"style":86},[72,386,142],{"style":82},[72,388,145],{"style":78},[72,390,148],{"style":82},[72,392,393,395,398,401,404,406,408,410,412,414,416,418,420,422,424,427],{"class":74,"style":75},[72,394,153],{"style":82},[72,396,397],{"style":78},"const ",[72,399,400],{"style":86},"response ",[72,402,403],{"style":78},"= ",[72,405,156],{"style":78},[72,407,159],{"style":121},[72,409,136],{"style":82},[72,411,170],{"style":86},[72,413,40],{"style":78},[72,415,180],{"style":82},[72,417,183],{"style":78},[72,419,83],{"style":82},[72,421,188],{"style":82},[72,423,183],{"style":78},[72,425,426],{"style":96},"'missing' ",[72,428,429],{"style":82},"} })",[72,431,432,434,436,438,441,443,446,449,451,454,456,459],{"class":74,"style":75},[72,433,153],{"style":82},[72,435,341],{"style":121},[72,437,125],{"style":82},[72,439,440],{"style":86},"response",[72,442,60],{"style":78},[72,444,445],{"style":121},"status",[72,447,448],{"style":82},"())",[72,450,60],{"style":78},[72,452,453],{"style":121},"toBe",[72,455,125],{"style":82},[72,457,458],{"style":82},"404",[72,460,461],{"style":82},")",[72,463,464,466,468,470,472,474,476,479,481,483,486,488,491],{"class":74,"style":75},[72,465,153],{"style":82},[72,467,341],{"style":121},[72,469,125],{"style":82},[72,471,156],{"style":78},[72,473,440],{"style":86},[72,475,60],{"style":78},[72,477,478],{"style":121},"text",[72,480,448],{"style":82},[72,482,60],{"style":78},[72,484,485],{"style":121},"toContain",[72,487,125],{"style":82},[72,489,490],{"style":96},"'not found'",[72,492,461],{"style":82},[72,494,495],{"class":74,"style":75},[72,496,243],{"style":82},[11,498,499,500,503,504,507,508,510],{},"HTTP error statuses resolve by default. Set ",[23,501,502],{},"options.failOnStatusCode: true"," to make Playwright reject them instead. A ",[23,505,506],{},"204"," response stays empty, and ",[23,509,321],{}," on it follows Playwright's own parsing. Network errors propagate unchanged.",[11,512,513,514,516,517,520],{},"The ",[23,515,321],{}," type is the success response type from ",[23,518,519],{},"@kubb\u002Fplugin-ts",". It does not describe error bodies and does not validate the data received.",{"title":522,"searchDepth":523,"depth":523,"links":524},"",5,[525,527],{"id":17,"depth":526,"text":18},2,{"id":301,"depth":526,"text":302},"\u002Fextensions\u002Fericlm\u002Fkubb-plugin-playwright\u002Fguides\u002Fnative-options-and-responses",1793488215108]