Skip to content

Commit

Permalink
wip: show use of fetch api in test
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Dec 7, 2023
1 parent eb3110c commit 7cfd7d5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
8 changes: 4 additions & 4 deletions examples/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export class DogService {
this.port = endpoint.port;
}

public getMeDogs = (): AxiosPromise => {
return axios.request({
baseURL: `${this.url}:${this.port}`,
public getMeDogs = async (): Promise<any> => {
const res = await fetch(`${this.url}:${this.port}/dogs`, {
headers: { Accept: 'application/json' },
method: 'GET',
url: '/dogs',
});

return res.json();
};
}
59 changes: 30 additions & 29 deletions examples/typescript/test/get-dog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,39 +65,40 @@ describe('The Dog API', () => {

it('returns the correct response', (done) => {
dogService.getMeDogs().then((response: any) => {
expect(response.data[0]).to.deep.eq(dogExample);
console.log(response);
expect(response[0]).to.deep.eq(dogExample);
done();
}, done);
});
});

describe('get /dogs using object pattern', () => {
before(() => {
return provider.addInteraction({
state: 'i have a list of dogs',
uponReceiving: 'a request for all dogs with the object pattern',
withRequest: {
method: 'GET',
path: '/dogs',
headers: {
Accept: 'application/json',
},
},
willRespondWith: {
status: 200,
headers: {
'Content-Type': 'application/json',
},
body: EXPECTED_BODY,
},
});
});
// describe('get /dogs using object pattern', () => {
// before(() => {
// return provider.addInteraction({
// state: 'i have a list of dogs',
// uponReceiving: 'a request for all dogs with the object pattern',
// withRequest: {
// method: 'GET',
// path: '/dogs',
// headers: {
// Accept: 'application/json',
// },
// },
// willRespondWith: {
// status: 200,
// headers: {
// 'Content-Type': 'application/json',
// },
// body: EXPECTED_BODY,
// },
// });
// });

it('returns the correct response', (done) => {
dogService.getMeDogs().then((response: any) => {
expect(response.data[0]).to.deep.eq(dogExample);
done();
}, done);
});
});
// it('returns the correct response', (done) => {
// dogService.getMeDogs().then((response: any) => {
// expect(response.data[0]).to.deep.eq(dogExample);
// done();
// }, done);
// });
// });
});

0 comments on commit 7cfd7d5

Please sign in to comment.