小编mee*_*kat的帖子

Jest moduleNameMapper 查找文件:“resolver”:未定义

component我在路径下的文件夹中有一个文本文件(除其他外) :src/components/text

\n

import Text from "components/text";但是,当使用webpack 别名时,Jest 找不到该文件。

\n

我尝试添加到package.json

\n
\n"jest": {\n    "globals": {\n      "NODE_ENV": "test"\n    },\n    "transform": {\n      "\\\\.[jt]sx?$": "babel-jest"\n    },\n    "verbose": false,\n    "rootDir": ".",\n    "collectCoverageFrom": [\n      "**/*.{js,jsx,ts,tsx}",\n      "!**/*.d.ts"\n    ],\n    "moduleFileExtensions": [\n      "js",\n      "jsx",\n      "ts",\n      "tsx"\n    ],\n    "moduleNameMapper": {\n      "\\\\.(css|less|scss|sass|svg)$": "identity-obj-proxy",\n      "^components/(.*)$": "<rootDir>/src/components/$1",\n      "^assets/(.*)$": "<rootDir>/src/assets/$1",\n      "^utils/(.*)$": "<rootDir>/src/utils/$1",\n      "^styles/(.*)$": "<rootDir>/src/styles/$1"\n      "/^locales\\/(.*)$/": "<rootDir>/src/locales/$1",\n    },\n    "testMatch": [\n      "**/*.{spec,test}.{js,jsx,ts,tsx}"\n    ],\n    "modulePathIgnorePatterns": [\n      "./dist"\n    ],\n    "transformIgnorePatterns": [\n      "/node_modules/(?!(@opt-ui|@equinor))"\n    ],\n    "coverageDirectory": "<rootDir>/tests/coverage/"\n  }\n
Run Code Online (Sandbox Code Playgroud)\n

但我收到错误:

\n
Test suite …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs package.json

15
推荐指数
1
解决办法
2万
查看次数

跳过 Azure DevOps 中的管道阶段

问题

当触发下面的管道时,在Build 和 push之后不会运行Dev阶段。

在此输入图像描述

该管道由以开发为目标分支的 PR 触发。

管道.yaml

trigger:
  branches:
    include:
      - master
      - develop

pr:
  branches:
    include:
      - develop

stages:
  # Frontend tests: Triggered by opening new PRs to develop or updating pr to develop.
  - stage: FrontEndTests
    displayName: "Frontend tests"
    condition: eq( variables['Build.Reason'], 'PullRequest') #  Trigger stage only for PullRequests
    jobs:
      - template: /templates/pipelines/npm-unit-tests.yml@templates
        parameters:
          triggerType: ${{ variables.triggerType }}

  # Common build triggered by push to master or develop
  - stage: BuildPush
    displayName: "Build …
Run Code Online (Sandbox Code Playgroud)

azure docker azure-devops azure-pipelines

10
推荐指数
1
解决办法
1万
查看次数

使用 Dockerfile 运行 Jest 测试

问题

\n

嘿,我没有太多使用 Docker - 我正在尝试通过 Dockerfile 运行我的 Jest 测试。然而,我error在尝试构建图像时得到了这个:

\n

错误

\n
Step 13/16 : RUN if [ "$runTests" = "True" ]; then     RUN npm test; fi\n ---> Running in ccdb3f89fb79\n/bin/sh: RUN: not found\n
Run Code Online (Sandbox Code Playgroud)\n

Dockerfile

\n
FROM node:10-alpine as builder\nARG TOKEN\nWORKDIR /app\n\nARG runTests\n\n\nCOPY .npmrc-pipeline .npmrc\n\nCOPY package*.json ./\nRUN npm install\nCOPY . .\n\nRUN rm -f .npmrc\n\nENV PORT=2000\nENV NODE_ENV=production\n\n\nRUN if [ "$runTests" = "True" ]; then \\\n    RUN npm test; fi\n\nRUN npm run build\n\nEXPOSE 2000\n\nCMD ["npm", "start"]\n
Run Code Online (Sandbox Code Playgroud)\n

我用来构建图像的命令是这样的,其想法是仅当 …

docker reactjs jestjs dockerfile

7
推荐指数
1
解决办法
2万
查看次数

Jest 的模拟常量不起作用(同一测试文件中的多个模拟)

我遇到的问题是,模拟的常量在之后的组件中不会改变jest.doMock

看一下最小的仓库

我尝试过用-mock代替doMock- 同样的错误。

应用程序.test.js

import React from "react"
import App from './App'
import '@testing-library/jest-dom'
import { render } from "@testing-library/react";

describe('testing app.js', () => {

  // To reset manually mocked values
  beforeEach(() => {
    jest.resetModules()
  });

  test("SET CONSTANT TO 1", () => {
    jest.doMock('./myConstants.js', () => ({
      CONSTANT: {
        NUMBER: 1
      }
    }))
    const { getByText, getByLabelText } = render(<App />)
    expect(getByText('1')).toBeInTheDocument()

  })

  test("SET CONSTANT TO 3", () => {
    jest.doMock('./myConstants.js', …
Run Code Online (Sandbox Code Playgroud)

mocking reactjs jestjs react-testing-library

6
推荐指数
1
解决办法
1万
查看次数

绘图时忽略 Matplotlib rcParams

我正在使用 matplotlib 3.2.2 版和 tkinter 编写交互式绘图脚本。

运行脚本时,第一个窗口如下所示: 在此处输入图片说明 此外,一旦单击Plot figure e 按钮,rcParams 就会更新和绘制:

在此处输入图片说明

如果我现在点击按钮更改绘图设置并更改例如markersize参数 -> Plot figure,则绘图更新如下:

在此处输入图片说明

但是,如果我尝试将标签大小更改为 20 像素,然后验证 rcParams['axes.labelsize']已更改,则它们是。但是 x 和 y 标签的大小在实际绘图中永远不会更新。

绘图标题(一直到绘图窗口顶部的文本输入字段)字体大小可以在绘图后更改。

最小代码:

"""
This is a script for interactively plotting a scatterplot and changing the plot params.
"""

import numpy as np
import matplotlib as mpl
import matplotlib.style
import random

mpl.use('TkAgg')
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import *
import matplotlib.pyplot as plt …
Run Code Online (Sandbox Code Playgroud)

python tkinter matplotlib tkinter-canvas tkinter-entry

5
推荐指数
1
解决办法
289
查看次数

React测试库找不到可点击元素(通过点击对表进行排序)

我想要做的是测试单击表标题列是否使用React 测试库first对表的行进行排序。我模拟了一些似乎渲染得很好的数据。

注意:我很确定这与所使用的组件无关,所以我没有费心将其放在这里。

在此输入图像描述

问题

但是,当我使用 React 测试库(应该对行进行排序)触发单击事件时,行不会排序。

似乎没有找到正确的元素。

这是浏览器中的组件树:

在此输入图像描述

代码

describe("Testing fullscring timp table", () => {
  let mockData = [];
  let columns = [];
  let store;
  let history;
  let mockStore;
  let global;

  beforeAll(() => {
    // column definitions for the Table component
    columns = [
      { dataKey: "1", title: "first", dataIndex: 1 },
      { dataKey: "2", title: "second", dataIndex: 2 },
      { dataKey: "3", title: "third", dataIndex: 3 },
      { dataKey: "4", title: "fourth", dataIndex: 4 …
Run Code Online (Sandbox Code Playgroud)

unit-testing reactjs react-testing-library

5
推荐指数
1
解决办法
1525
查看次数

在 beforeAll/beforeEvery 中渲染相同的组件:testing-library/react

我在单独的测试中在单个组件中测试不同的东西。我不想在每个单独的内部编写 render test,但是下面的代码不起作用。

我知道清理功能会在每次测试后清除渲染的组件,所以这很好。

import React from "react";
import { Router } from "react-router-dom";
import { render } from "@testing-library/react";
import "@testing-library/jest-dom";

import myComp from './myComp'

const renderComponent = () => {
  return render(<myComp />);
};

describe("desc", () => {
  beforeEach(() => {
   const {getAllByText, getByText, getByRole} = renderComponent()
  });

  test("1", () => {
      console.log(getAllByText) // not defined
  });

  test("2", () => {
      console.log(getAllByText) // not defined

  });

})
Run Code Online (Sandbox Code Playgroud)

上面的设置会导致错误:

ReferenceError: getAllByText is not defined
Run Code Online (Sandbox Code Playgroud)

renderComponent()我当前的解决方法是在 every 中包含函数调用 …

components reactjs jestjs react-testing-library

4
推荐指数
1
解决办法
9336
查看次数