fetch-wrap
fetch-wrap copied to clipboard
Can merge be replaced by ES6 destructuring?
I wonder if the usage of lodash/merge is obsolete for the operations most middlewares do here? They usually don't do deep merges so couldn't
return fetch(url, extendedFetch.merge({}, options, {
headers: {
"Authorization": "Bearer ...",
}
}))
be replaced with:
return fetch(url, {
...options,
headers: {
...options.headers,
"Authorization": "Bearer ...",
}
}))
it.only("should not matter", () => {
const options = {
body: "Test",
headers: {
"Accept": "text/plain",
},
}
expect(extendFetch.merge({}, options, {
headers: {
"Content-Type": "text/plain",
},
})).toEqual({
...options,
headers: {
...options.headers,
"Content-Type": "text/plain",
},
})
})