A
A
asd dsa2020-05-19 19:25:26
JavaScript
asd dsa, 2020-05-19 19:25:26

Why am I getting the error: "TypeError: Object.fromEntries is not a function?" when running a unit test?

I have this method: "dataToExportInFile" it works correctly, but when I want to write a unit test for this method, I get an error: TypeError: Object.fromEntries is not a functioneven when I want to console the value of this method in the unit test. Please tell me what is the problem and how to solve it.

dataToExportInFile() {
            if (this.dps.length === 0 || this.legends.length === 0) {
                return null
            }
            const extractLegendsValue = Object.fromEntries(this.legends.map(n => [n.id, n])) // на эту строку ругается 
            const mergeData = this.dps.map(n => ({ ...n, ...extractLegendsValue[n.y] }))
            const formattedData = mergeData.map((en) => {
                const extractAggregator = en.id.substring(en.id.lastIndexOf("_") + 1)
                return {
                    time: new Date(en.timestamp).toISOString(),
                    entityId: en.isAggregated ? "" : en.entityId,
                    name: en.isAggregated ? `${en.text} (${this.friendlyAggregatorNames[extractAggregator]})` :
                        en.secondaryText,
                    value: en.value,
                    entityName: !en.isAggregated ? en.text : ""
                }
            })
            return {
                value: {
                    mime: "text/csv",
                    data: formattedData,
                    friendlyHeaderNames: ["Time", "Entity ID", "Metric Name", "Value", "Entity Name"]
                }
            }


unit test code, if you're interested

import Vuex from "vuex"
import { shallowMount, createLocalVue } from "@vue/test-utils"
import ZDashTimeseries from "../../tileComponents/ZDashTimeseries"
import Component from "./Component"

const localVue = createLocalVue()
localVue.use("z-dash-timeseries", ZDashTimeseries)
localVue.use(Vuex)

const stubs = ["resize-observer"]
const mockedchartDpsColorMap = {
    mem_MemUsedPercent_MEAN: "#9467bd",
    "AAAAAQ5qdjQoZBpkVZoIqpu1pRU=": "#2ca02c",
    "AAAAAR0m8bvTuGrubL3V57UYlv4=": "#bcbd22"
}

describe("GraphTile Component", () => {
    let testStore

    beforeEach(() => {
        const getters = {
            userTenant: () => "qapreview",
            chartDpsColorMap: () => mockedchartDpsColorMap,
            scopeCount: () => 11053
        }
        testStore = new Vuex.Store({
            modules: {
                dashboard: {
                    namespaced: true,
                    getters
                }
            }
        })
    })
    it("The data in the CSV file is limited to what is visible in the graph tile", () => {
        const wrapper = shallowMount(Component, {
            mocks: {
                $apollo: {
                    queries: {
                        metrics: {
                            loading: false,
                        },
                    },
                },
                measureEl: () => {}
            },
            stubs,
            localVue,
            store: testStore,
            sync: false,
            data() {
                return {
                    metrics: mockedMetrics,
                }
            },
        })
        console.log(wrapper.vm.menuOptions)
    })
})

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question