0

我有组件 Componnent1 并且在 componentDidMount 内部我有以下代码:-

const key1 = sessionStorage.getItem("key1");
    FHIR.oauth2
      .ready()
      .then((client) =>
        client.request("<url>/" + key1, {
          resolveReferences: [
          ],
          graph: true,
        })
      )
      .then((json) => {
        console.log(json);
      })
      .catch(console.error);

我收到了这个错误

● 按预期呈现

console.error internal/process/next_tick.js:68 TypeError: client.request is not a function at _fhirclient.default.oauth2.ready.then.client (C:\Users\dbdeb\OneDrive\Desktop\patient-application\src \components\my-health-deatails.component\allergies.component\allergies.js:68:16) 在 process._tickCallback (internal/process/next_tick.js:68:7)

我的测试用例就像:-

import { Component1} from "../component1"
import React, { Component } from "react";
import { render } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect'
import FHIR from "fhirclient";
jest.mock('fhirclient', () => ({
    oauth2: {
        ready: jest.fn(() => Promise.resolve({
            client: {
                request: jest.fn(() => { return { data: null } })
            }
        }))
    }
}));
test('renders as expected', () => {
    FHIR.oauth2.ready.mockResolvedValueOnce({ data: { entry: '' } })
    render(<Component1></Component1>)
});
4

0 回答 0