OfficeDev / OfficeDev/Office-Addin-Scripts

Unable to use OfficeMockObject in jsdom test environment

Đang mở
#653 9 bình luận 0 reaction 1 người được giao Xem trên GitHub

@igor-ribeiiro đang làm issue này rồi.

Từ ngày 21/6/2022.

triaged
Ngôn ngữ chính
TypeScript
Star
194
Fork
117
Merge trung bình
1 ngày 32 phút
Pull request đã merge (30 ngày)
2

Mô tả

Prerequisites

  • I am running the latest version of Node and the tools
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected behavior

The jest test runner runs the tests with jsdom environment without error while making use of "office-addin-mock".

Current behavior

The test fails to run because "office-addin-mock" seems to expect a Node environment (see Failure Logs below).

Steps to Reproduce

Run the following test file:

/**
 * @jest-environment jsdom
 */

import React from "react";
import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import { OfficeMockObject } from "office-addin-mock";
import App from "./App";

/* global global, it, expect */

const officeMock = new OfficeMockObject({});
// @ts-ignore
global.Office = officeMock;

it("should render message while fetching contact(s)", () => {
  render(<App title={"Some Title"} isOfficeInitialized={true} />);

  expect(screen.getByRole("header")).toHaveTextContent("Whatever");
});

Context

Packages installed in addition to the office-addin-react starter:

  • "@testing-library/jest-dom": "^5.16.4",
  • "@testing-library/react": "^12.1.5",
  • "@types/jest": "^28.1.1",
  • "jest": "^28.1.1",
  • "jest-environment-jsdom": "^28.1.1",
  • "office-addin-mock": "^2.1.2",
  • "ts-jest": "^28.0.5",
  • Operating System: Windows
  • Node version: v16.15.0

jest.config.js:

const config = {
  preset: "ts-jest",
  testEnvironment: "node",
};
module.exports = config;

Test script: jest

Failure Logs

● Test suite failed to run

    The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/configuration#testenvironment-string.
    Consider using the "node" test environment.
    
    TypeError: this._handle.unref is not a function

       6 | import { render, screen } from "@testing-library/react";
       7 | import "@testing-library/jest-dom";
    >  8 | import { OfficeMockObject } from "office-addin-mock";
         | ^
       9 | import App from "./App";
      10 |
      11 | /* global global, it, expect */

      at new OfficeAddinUsageData (node_modules/office-addin-usage-data/src/usageData.ts:126:13)
      at Object.<anonymous> (node_modules/office-addin-manifest/src/defaults.ts:7:64)
      at Object.<anonymous> (node_modules/office-addin-manifest/src/manifestOperations.ts:4:1)
      at Object.<anonymous> (node_modules/office-addin-manifest/src/main.ts:7:1)
      at Object.<anonymous> (node_modules/office-addin-mock/src/officeMockObject.ts:1:1)
      at Object.<anonymous> (node_modules/office-addin-mock/src/main.ts:4:1)
      at Object.<anonymous> (src/taskpane/components/minimal.test.tsx:8:1)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:317:13)
      at runJest (node_modules/@jest/core/build/runJest.js:407:19)
      at _run10000 (node_modules/@jest/core/build/cli/index.js:339:7)
      at runCLI (node_modules/@jest/core/build/cli/index.js:190:3)

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.