Как подключить компонент React к огурцу. js? - PullRequest
0 голосов
/ 03 августа 2020

Я хочу запустить React в Cucumberjs Я создал класс Word, в котором я подключил компонент приложения

import { setWorldConstructor } from 'cucumber'
import {render } from '@testing-library/react'
import React from 'react'
import App from '../../App'

class AppWorld {

    
    constructor () {
        
        let {queryByText,queryByLabelText,queryByTestId} = render(<App/>)
        this._queryByText =   queryByText
        this._queryByLabelText = queryByLabelText
        this._gueryByTestId = queryByTestId  
    }

    getQueryByText() {
        return this._queryByText
    }

    getQueryByLabelText() {
        return this._queryByLableText
    }

    getQueryByTestId() {
        return this._queryByTestId 
    }

}

setWorldConstructor(AppWorld);

Я также сделал файл конфигурации cucumber js

module.exports = {
  default: [
    'src/features/**/*.feature',
    '--require ./features/worlds/AppWorld.js',
      '--require ./features/support/index.js',
      '--require src/features/**/*.js',
    '--require-module @babel/register'
  ].join(' '),
};

> The package.json is

 

     "name": "todofrontenf",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "@babel/preset-env": "^7.11.0",
        "@babel/preset-react": "^7.10.4",
        "bootstrap": "^4.5.0",
        "dotenv": "^8.2.0",
        "jest-fetch-mock": "^3.0.3",
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
        "react-router-dom": "^5.2.0",
        "react-scripts": "^3.4.1",
        "use-react-router": "^1.0.7",
        "winston": "^3.3.3",
        "winston-elasticsearch": "^0.7.12"
      },
      "scripts": {
        "start:devsource": "DOTENV_CONFIG_BACKEND_URL=http://localhost:8080 node -r dotenv/config ./node_modules/react-scripts/bin/react-scripts.js start",
        "start:devbuild": "PORT=9000 node -r dotenv/config server.js dotenv_config_path=.env.dev",
        "prestart": "npm build",
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "cucumber": "./node_modules/.bin/cucumber-js src/features/**/*.feature --require=src/features/**/*.js --require-module @babel/register",
        "test:build": "node -r dotenv/config ./node_modules/react-scripts/bin/react-scripts.js test ./src dotenv_config_path=.env.build",
        "test:dev": "node -r dotenv/config ./node_modules/react-scripts/bin/react-scripts.js test ./src dotenv_config_path=.env.dev",
        "test:test": "node -r dotenv/config ./node_modules/react-scripts/bin/react-scripts.js test ./src dotenv_config_path=.env.test",
        "eject": "react-scripts eject"
      },
      "eslintConfig": {
        "extends": "react-app"
      },
      "browserslist": {
        "production": [
          ">0.2%",
          "not dead",
          "not op_mini all"
        ],
        "development": [
          "last 1 chrome version",
          "last 1 firefox version",
          "last 1 safari version"
        ]
      },
      "devDependencies": {
        "@babel/register": "^7.10.5",
        "@reportportal/agent-js-jest": "^5.0.1",
        "@testing-library/jest-dom": "^5.11.0",
        "@testing-library/react": "^10.4.6",
        "cucumber": "^6.0.5",
        "enzyme": "^3.11.0",
        "enzyme-adapter-react-16": "^1.15.2",
        "jest-sonar-reporter": "^2.0.0"
      }
    }

Я получаю следующее сообщение, когда выполняю npm run cucumber

Steins-MacBook-Air: todofrontend steinkorsveien $ npm run огурец

> todofrontenf@0.1.0 cucumber /Users/steinkorsveien/Development/todo/todofrontend
> cucumber-js src/features/**/*.feature --require=src/features/**/*.js --require-module @babel/register

ReferenceError: document is not defined
    at render (/Users/steinkorsveien/Development/todo/todofrontend/node_modules/@testing-library/react/dist/pure.js:82:5)
    at new AppWorld (/Users/steinkorsveien/Development/todo/todofrontend/src/features/worlds/AppWorld.js:11:60)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! todofrontenf@0.1.0 cucumber: `cucumber-js src/features/**/*.feature --require=src/features/**/*.js --require-module @babel/register`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the todofrontenf@0.1.0 cucumber script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

Как мне настроить Cucumber js для тестирования React?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...