Skip to content

Commit

Permalink
fix ajax tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Jun 11, 2024
1 parent 9feb359 commit 4933817
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export function attachCallbacks(fetchPm, callback) {
success: typeof callback === 'function' ? callback : () => null,
error: (e, x) => logError('Network error', e, x)
};
fetchPm.then(response => response.text().then((responseText) => [response, responseText]))
return fetchPm.then(response => response.text().then((responseText) => [response, responseText]))
.then(([response, responseText]) => {
const xhr = toXHR(response, responseText);
response.ok || response.status === 304 ? success(responseText, xhr) : error(response.statusText, xhr);
Expand Down
32 changes: 15 additions & 17 deletions test/spec/unit/core/ajax_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,24 +405,22 @@ describe('attachCallbacks', () => {
}).forEach(([cbType, makeResponse]) => {
it(`do not choke ${cbType} callbacks`, () => {
const {response} = makeResponse();
return new Promise((resolve) => {
const result = {success: false, error: false};
attachCallbacks(Promise.resolve(response), {
success() {
result.success = true;
throw new Error();
},
error() {
result.error = true;
throw new Error();
}
const result = {success: false, error: false};
return attachCallbacks(Promise.resolve(response), {
success() {
result.success = true;
throw new Error();
},
error() {
result.error = true;
throw new Error();
}
}).catch(() => null)
.then(() => {
Object.entries(result).forEach(([typ, ran]) => {
expect(ran).to.be[typ === cbType ? 'true' : 'false'];
});
});
setTimeout(() => resolve(result), 20);
}).then(result => {
Object.entries(result).forEach(([typ, ran]) => {
expect(ran).to.be[typ === cbType ? 'true' : 'false']
})
});
});
});
});
Expand Down

0 comments on commit 4933817

Please sign in to comment.