working flat() polyfill for jest

This commit is contained in:
Michael Shanks 2020-08-27 10:20:01 +01:00
parent 54e0a48701
commit 94935b023b
3 changed files with 28 additions and 6 deletions

View File

@ -49,6 +49,9 @@
],
"setupFilesAfterEnv": [
"@testing-library/jest-dom/extend-expect"
],
"setupFiles": [
"./scripts/jestSetup.js"
]
},
"eslintConfig": {

View File

@ -0,0 +1,25 @@
if (!Array.prototype.flat) {
Object.defineProperty(Array.prototype, "flat", {
configurable: true,
value: function flat() {
var depth = isNaN(arguments[0]) ? 1 : Number(arguments[0])
return depth
? Array.prototype.reduce.call(
this,
function(acc, cur) {
if (Array.isArray(cur)) {
acc.push.apply(acc, flat.call(cur, depth - 1))
} else {
acc.push(cur)
}
return acc
},
[]
)
: Array.prototype.slice.call(this)
},
writable: true,
})
}

View File

@ -1,10 +1,4 @@
import fetchBindableProperties from "../src/builderStore/fetchBindableProperties"
import { flat } from "lodash"
// supports running jest on Node 10.x
if (!Array.flat) {
Array.flat = flat
}
describe("fetch bindable properties", () => {