yaNastia
@yaNastia

Почему я получаю ошибку: «TypeError: Object.fromEntries is not a function?» при запуске юнит теста?

У меня есть этот метод: "dataToExportInFile"он работает правильно, но когда я хочу написать юнит тест для этого метода, я получаю ошибку: TypeError: Object.fromEntries is not a function, даже когда хочу вывести в консоль значение этого метода в юнит тесте. Подскажите пожалуйста в чем проблема и как решить.
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"]
                }
            }


код с юнит теста, если интересно

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)
    })
})
  • Вопрос задан
  • 1192 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы