1
0
Fork 0
mirror of synced 2024-06-18 18:35:37 +12:00

working flat() polyfill for jest

This commit is contained in:
Michael Shanks 2020-08-27 10:20:01 +01:00
parent e5e81aa9c6
commit f16a29792c
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", () => {