Skip to content

Instantly share code, notes, and snippets.

@DoctorDerek
Created September 8, 2022 15:35
Show Gist options
  • Save DoctorDerek/acb679d1b3cdf30f254f1828d4b18caa to your computer and use it in GitHub Desktop.
Save DoctorDerek/acb679d1b3cdf30f254f1828d4b18caa to your computer and use it in GitHub Desktop.
Why You Should Always Pass Objects as Function Parameters in JavaScript https://medium.com/p/7fb7c5833dc6
// @/__tests__/utils/getChartOptions.spec.js
describe("@/utils/getChartOptions", () => {
const chartData = [1, 2, 3]
const defaultChart = getDefaultChart(chartData)
it("passes along defaultChart only without extraOptions", () => {
const output = getChartOptions(chartData)
expect(output).toBe(defaultChart)
})
it("passes along defaults and extraOptions", () => {
const extraOptions = {
series: [
{
type: "gauge",
pointer: {
show: true,
},
},
],
}
const output = getChartOptions(
defaultChart,
undefined,
undefined,
undefined,
undefined,
extraOptions
)
expect(output).toBe({ ...defaults, ...extraOptions })
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment