小编Ahm*_*nto的帖子

CORS BLOCKED 'Access-Control-Allow-Origin' Firebase 功能不允许

将数据发送到firebase数据库时出现错误:

从源“ http://localhost:3030 ”获取“ https://us-central1-pwagram-f39a5.cloudfunctions.net/storePostData ”的访问权限已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。如果不透明响应满足您的需求,请将请求的模式设置为“no-cors”以在禁用 CORS 的情况下获取资源

我使用改变了终点的时候有这个问题,cors部署后firebase。但是在本地主机上运行时只有一个错误。我需要它在本地主机上工作,因为我仍在使用它进行开发。

首先,我运行: npm install firebase-admin cors --save

这是我关于文件夹功能的package.jsonfirebase

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "dependencies": {
    "cors": "^2.8.5",
    "firebase-admin": "^8.9.1",
    "firebase-functions": "^3.3.0"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": …
Run Code Online (Sandbox Code Playgroud)

javascript grand-central-dispatch cors firebase

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

React 测试库类型错误:无法在“EventTarget”上执行“removeEventListener”:需要 2 个参数,但仅存在 1 个

我有一个有事件的反应类组件

constructor(props) {
    super(props);

    this.monthRef = React.createRef();
    this.yearRef = React.createRef();

    this.state = {
      moIndexActive: props.initialMonth - 1,
      yeIndexActive: years.findIndex(y => y === `${props.initialYear}`),
    };
  }
//some code blablabla
// this error occur in this line bellow
  componentWillUnmount() {
    this.monthRef.current.removeEventListener('scroll');
    this.yearRef.current.removeEventListener('scroll');
  }
Run Code Online (Sandbox Code Playgroud)

该组件用于功能组件,当我测试功能组件时出现错误消息 在此输入图像描述

我正在使用 React 测试库来测试这个,我已经在谷歌上搜索过,但还没有找到解决方案,请帮助我。如果有任何方法可以模拟React测试库或Jest上的removeEventListener。提前致谢。

reactjs jestjs react-testing-library

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