收到此错误
匹配器错误:接收的值必须是模拟或间谍函数
Run Code Online (Sandbox Code Playgroud)Received has type: object Received has value: {}
但是,我认为我不应该收到此错误,因为我正在使用jest.fn. 所以我在嘲笑这个功能。
describe('Should simulate button click', ()=> {
it('should simulate button click', () => {
// add the name of the prop, which in this case ites called onItemAdded prop,
// then use jest.fn()
const wrapper = shallow(<TodoAddItem onItemAdded={() => jest.fn()}/>)
// console.log('props',wrapper.find('button').props());
wrapper.find('button').simulate('click');
expect(wrapper).toHaveBeenCalled(); // error happens when this executes
})
})
Run Code Online (Sandbox Code Playgroud)
todo-add-item.js
import React, { Component } from 'react';
import './todo-add-item.css';
export default class TodoAddItem extends …Run Code Online (Sandbox Code Playgroud) 尝试对用户进行身份验证时出现 401 错误。只是为了提供上下文,React 使用 Express 服务器,并使用 Passport 进行身份验证。React 的端口为8001,Express 服务器的端口为8000。
GET /api/users/user 401 2.167 毫秒 - 59
其他 get 请求 做工作。例如
反应
export const getUser = () => {
return async (dispatch) =>{
Axios.get('/api/users/user')
.then( (res) => {
console.log(res.data);
localStorage.setItem('auth', res.data.authenticated);
dispatch({type: GET_USER, res});
}).catch( (err) => {
console.log(err);
})
}
}
Run Code Online (Sandbox Code Playgroud)
公理
import Axios from 'axios'
let AxiosInstance = Axios.create({
baseURL: process.env.REACT_APP_BASE_URL, // http://localhost:8000
withCredentials: true,
headers: {
'Content-Type': 'application/json',
},
})
// AxiosInstance.defaults.headers.post['Content-Type'] = …Run Code Online (Sandbox Code Playgroud) 在进行 docker-compose up 时,出现以下错误。应用程序正在运行,但无法发出任何 api post/get 请求。Express 服务器使用端口 5000。
] [HPM] 尝试将请求 /api/users/user 从 localhost:3000 代理到http://localhost:5000/时出错(ECONNREFUSED)(https://nodejs.org/api/errors.html#errors_common_system_errors)
尽管设置了反应代理,但错误仍然存在。
setupProxy.js
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
// app.use(proxy('/auth/github', { target: 'http://localhost:3000/' }))
app.use(proxy('/api/users/auth/github', { target: 'http://localhost:5000/' }))
app.use(proxy('/api/users/', { target: 'http://localhost:5000/' }))
app.use(proxy('/api/posts/', { target: 'http://localhost:5000/' }))
}
Run Code Online (Sandbox Code Playgroud)
Dockerfile
FROM node:8.10.0-alpine
EXPOSE 3000
COPY . /home/app
WORKDIR /home/app
RUN npm install
CMD ["npm", "start"]
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml
# docker-compose.yml
version: "3"
services:
app:
build: .
depends_on:
- postgres …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的应用程序推送到 Heroku,但遇到了一些问题:
错误:ENOENT:没有这样的文件或目录,打开“.env”2019-04-10T01:38:23.050188 + 00:00 app [web.1]:1 在Object.openSync(fs.js:438:3)2019 -04-10T01:38:23.050190+00:00 app[web.1]: 1 at Object.readFileSync (fs.js:343:35) 2019-04-10T01:38:23.050192+00:00 app[web.1] 1]:1 在对象处。(/app/config/database.js:4:39)
看来错误是变量envConfig,但我需要它才能使数据库正常工作。
截至目前,我得到
这是我的config/database.js:
if (!process.env.PG_DB) {
const fs = require('fs')
const dotenv = require('dotenv')
// dotenv, but i need this make the database work
const envConfig = dotenv.parse(fs.readFileSync('.env'))
for (var k in envConfig) {
process.env[k] = envConfig[k]
}
console.log('[api][sequelize] Loaded database ENV vars from .env file')
}
module.exports = {
development: {
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD, …Run Code Online (Sandbox Code Playgroud) Docker 正在使用我的 .env 文件中的变量,我不断收到错误消息:
未处理的拒绝 SequelizeConnectionError:角色“eli”不存在
我希望 Postgres 从设置的环境中获取变量 docker-compose.yml
.env
POSTGRES_PORT=5432
POSTGRES_DB=elitest4
POSTGRES_USER=eli
POSTGRES_PASSWORD=
Run Code Online (Sandbox Code Playgroud)
docker-compose.yml
# docker-compose.yml
version: "3"
services:
app:
build: .
depends_on:
- database
ports:
- 8000:8000
environment:
- POSTGRES_HOST=database
env_file:
- .env
database:
image: postgres:9.6.8-alpine
environment: # postgress should be getting these variables, not the variables set in the env file thats for localhost
POSTGRES_PASSWORD: password
POSTGRES_USER: user
POSTGRES_DB: db
volumes:
- pgdata:/var/lib/postgresql/pgdata
ports:
- 8002:5432
env_file:
- .env
react_client:
build:
context: ./client
dockerfile: Dockerfile
image: …Run Code Online (Sandbox Code Playgroud) 有一个问题,没有立即在 console.log 上更新状态,我必须在提交按钮上单击两次,以便 console.log 显示更新的状态
我检查了这个,但我认为这不是问题
工作演示,检查控制台
https://codesandbox.io/s/l499j0p5vm?fontsize=14
这是我所拥有的
应用程序.js
import React, {Component} from 'react';
import Navbar from './components/Navbar';
import {withStyles} from '@material-ui/core/styles';
import Paper from '@material-ui/core/Paper';
import Grid from '@material-ui/core/Grid';
import logo from './logo.svg';
import {Typography, Button} from '@material-ui/core';
import Footer from './components/Footer';
import Emoji from './components/Emoji';
import TextField from '@material-ui/core/TextField';
import EmojiPicker from 'emoji-picker-react';
import JSEMOJI from 'emoji-js';
import Icon from '@material-ui/core/Icon';
let jsemoji = new JSEMOJI();
// set the style to emojione (default - apple)
jsemoji.img_set …Run Code Online (Sandbox Code Playgroud) 尝试在 react 中使用 env 变量,我得到了一个
不明确的
我没有使用 webpack,只是使用 dotenv。不知道为什么它不起作用。
我参考了这个
它没有我正在寻找的解决方案。
包.json
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^3.9.1",
"@material-ui/icons": "^3.0.2",
"axios": "^0.18.0",
"history": "^4.7.2",
"http-proxy-middleware": "^0.19.1",
"material-ui-icons": "^1.0.0-beta.36",
"moment": "^2.24.0",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"react-redux": "^6.0.0",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.3",
"redux": "^4.0.1",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "PORT=8001 react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not …Run Code Online (Sandbox Code Playgroud) 单元测试代码时出现此错误,
2 通过 (14ms) 1 失败
js:552:3) at Module.require (internal/modules/cjs/loader.js:657:17) at require (internal/modules/cjs/helpers.js:22:18) at Object。(test/main.test.js:4:1) at Module._compile (internal/modules/cjs/loader.js:721:30) at Module._compile (node_modules/pirates/lib/index.js:99:24) ) 在 Module._extensions..js (internal/modules/cjs/loader.js:732:10) 在 Object.newLoader [as .js] (node_modules/pirates/lib/index.js:104:7) 在 Module。在 tryModuleLoad (internal/modules/cjs/loader.js:560:12) at Function.Module._load (internal/modules/cjs/loader.js: 552:3) at Module.require (internal/modules/cjs/loader.js:657:17) at require (internal/modules/cjs/helpers.js:22:18) at Array.forEach () at StatWatcher。
我正在使用mocha,并且--watch我的 package.json 上有。我正在使用 es6 方法来表达。
包.json
{
"name": "elies6express",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/mocha --watch --require @babel/register",
"start": "nodemon --exec babel-node main.js" …Run Code Online (Sandbox Code Playgroud) reactjs ×5
node.js ×4
express ×3
javascript ×3
docker ×2
axios ×1
enzyme ×1
heroku ×1
jestjs ×1
mocha.js ×1
passport.js ×1
postgresql ×1