BREAKING CHANGE(core): major architectural refactoring with fetch-like API
This commit is contained in:
@@ -7,7 +7,11 @@ tap.test('modern: should request a html document over https', async () => {
|
||||
.url('https://encrypted.google.com/')
|
||||
.get();
|
||||
|
||||
expect(response).toHaveProperty('body');
|
||||
expect(response).not.toBeNull();
|
||||
expect(response).toHaveProperty('status');
|
||||
expect(response.status).toBeGreaterThan(0);
|
||||
const text = await response.text();
|
||||
expect(text.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
tap.test('modern: should request a JSON document over https', async () => {
|
||||
@@ -15,8 +19,9 @@ tap.test('modern: should request a JSON document over https', async () => {
|
||||
.url('https://jsonplaceholder.typicode.com/posts/1')
|
||||
.get();
|
||||
|
||||
expect(response.body).toHaveProperty('id');
|
||||
expect(response.body.id).toEqual(1);
|
||||
const body = await response.json();
|
||||
expect(body).toHaveProperty('id');
|
||||
expect(body.id).toEqual(1);
|
||||
});
|
||||
|
||||
tap.test('modern: should post a JSON document over http', async () => {
|
||||
@@ -26,9 +31,10 @@ tap.test('modern: should post a JSON document over http', async () => {
|
||||
.json(testData)
|
||||
.post();
|
||||
|
||||
expect(response.body).toHaveProperty('json');
|
||||
expect(response.body.json).toHaveProperty('text');
|
||||
expect(response.body.json.text).toEqual('example_text');
|
||||
const body = await response.json();
|
||||
expect(body).toHaveProperty('json');
|
||||
expect(body.json).toHaveProperty('text');
|
||||
expect(body.json.text).toEqual('example_text');
|
||||
});
|
||||
|
||||
tap.test('modern: should set headers correctly', async () => {
|
||||
@@ -40,12 +46,12 @@ tap.test('modern: should set headers correctly', async () => {
|
||||
.header(customHeader, headerValue)
|
||||
.get();
|
||||
|
||||
|
||||
expect(response.body).toHaveProperty('headers');
|
||||
const body = await response.json();
|
||||
expect(body).toHaveProperty('headers');
|
||||
|
||||
// Check if the header exists (case-sensitive)
|
||||
expect(response.body.headers).toHaveProperty(customHeader);
|
||||
expect(response.body.headers[customHeader]).toEqual(headerValue);
|
||||
expect(body.headers).toHaveProperty(customHeader);
|
||||
expect(body.headers[customHeader]).toEqual(headerValue);
|
||||
});
|
||||
|
||||
tap.test('modern: should handle query parameters', async () => {
|
||||
@@ -56,11 +62,12 @@ tap.test('modern: should handle query parameters', async () => {
|
||||
.query(params)
|
||||
.get();
|
||||
|
||||
expect(response.body).toHaveProperty('args');
|
||||
expect(response.body.args).toHaveProperty('param1');
|
||||
expect(response.body.args.param1).toEqual('value1');
|
||||
expect(response.body.args).toHaveProperty('param2');
|
||||
expect(response.body.args.param2).toEqual('value2');
|
||||
const body = await response.json();
|
||||
expect(body).toHaveProperty('args');
|
||||
expect(body.args).toHaveProperty('param1');
|
||||
expect(body.args.param1).toEqual('value1');
|
||||
expect(body.args).toHaveProperty('param2');
|
||||
expect(body.args.param2).toEqual('value2');
|
||||
});
|
||||
|
||||
tap.test('modern: should handle timeout configuration', async () => {
|
||||
@@ -70,7 +77,8 @@ tap.test('modern: should handle timeout configuration', async () => {
|
||||
.timeout(5000);
|
||||
|
||||
const response = await client.get();
|
||||
expect(response).toHaveProperty('body');
|
||||
expect(response).toHaveProperty('ok');
|
||||
expect(response.ok).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('modern: should handle retry configuration', async () => {
|
||||
@@ -80,7 +88,8 @@ tap.test('modern: should handle retry configuration', async () => {
|
||||
.retry(1);
|
||||
|
||||
const response = await client.get();
|
||||
expect(response).toHaveProperty('body');
|
||||
expect(response).toHaveProperty('ok');
|
||||
expect(response.ok).toBeTrue();
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
Reference in New Issue
Block a user