我正在尝试使用react,redux-mock-store和redux编写一些测试,但我不断得到并且错误.也许是因为我Promise尚未解决?
fetchListing()当我在开发和生产上尝试它时,动作创建者实际上工作,但是我在测试通过时遇到了问题.
错误信息
(node:19143) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): SyntaxError
(node:19143) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
FAIL src/actions/__tests__/action.test.js
? async actions › creates "FETCH_LISTINGS" when fetching listing has been done
TypeError: Cannot read property 'then' of undefined
at Object.<anonymous> (src/actions/__tests__/action.test.js:44:51)
at Promise (<anonymous>)
at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:169:7)
async actions
? …Run Code Online (Sandbox Code Playgroud) 我正在尝试react-testing-library与 React 和 Jest一起使用,但我的一个测试失败了,我认为这与className prop测试文件上的正则表达式有关。
下面我附上了各自的测试和组件文件。
另外,有没有办法snapshot用这个库进行测试?我觉得我的测试由于某种原因没有完成。
// Image.js Component
// @flow
import * as React from "react";
import styled from "styled-components";
const StyledImage = styled.img`
max-width: ${props => props.imageWidth || 100}%;
`;
type Props = {
imageAlt: string,
imageSrc: string | boolean | Function,
className?: string,
StyledImage: React.Element<typeof StyledImage>
};
const Image = (props: Props) => {
const { imageAlt, imageSrc, className } = props;
return (
<StyledImage
{...props}
className={className}
src={imageSrc}
alt={imageAlt}
/> …Run Code Online (Sandbox Code Playgroud) 您好我想测试与材料的UI创建一个Slider组件,但我不能让我的测试通过。我想使用fireEventwith测试值的变化@testing-library/react。我一直在关注这篇文章以正确查询 DOM,但我无法获得正确的 DOM 节点。
提前致谢。
<Slider /> 成分
// @format
// @flow
import * as React from "react";
import styled from "styled-components";
import { Slider as MaterialUISlider } from "@material-ui/core";
import { withStyles, makeStyles } from "@material-ui/core/styles";
import { priceRange } from "../../../domain/Search/PriceRange/priceRange";
const Wrapper = styled.div`
width: 93%;
display: inline-block;
margin-left: 0.5em;
margin-right: 0.5em;
margin-bottom: 0.5em;
`;
// ommited code pertaining props and styles for simplicity
function Slider(props: SliderProps) {
const initialState = …Run Code Online (Sandbox Code Playgroud) 我正在尝试yup使用formik. 我的验证似乎有效,但我觉得它太冗长了。
试图使用 的.addMethod()功能yup,但在语法上陷入困境,或者这可能是矫枉过正?
摘要:我想将我的验证转换为使用yup.addMethod().
实际验证:
import * as yup from 'yup'
const countryNameRegex = /[A-Za-z]/g;
const countryCodeRegex = /[a-zA-Z]{2,}/g;
const isRequired = 'Required Field'
const isCorrectFormat = 'The country name may contain only letters'
const countryValidationSchema = yup.object().shape({
name: yup.string()
.min(3, `country name must contain at least 3 characters`)
.matches(
countryNameRegex,
{
message: isCorrectFormat,
excludeEmptyStrings: true
}
)
.label(`Country Name`)
.required(isRequired),
code: yup.string()
.length(2, `The country code must be …Run Code Online (Sandbox Code Playgroud) 大家好,我正在使用react-google-maps图书馆。每次我的位置发生变化时,我都试图重新调整我的地图(缩放标记所在的位置),但我对如何实现整个事情有点迷茫。我可以看到标记正在更新,但地图保持在其defaultCenter位置。
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
GoogleMap,
Marker,
withScriptjs,
withGoogleMap
} from 'react-google-maps';
import environment from '../../config/environment';
class Map extends Component {
static propTypes = {
defaultZoom: PropTypes.number,
center: PropTypes.shape({
lat: PropTypes.number,
lng: PropTypes.number
}),
location: PropTypes.shape({
lat: PropTypes.number,
lng: PropTypes.number
}),
onPositionChanged: PropTypes.func
};
static defaultProps = {
defaultZoom: 14,
center: {
lat: 60.1699,
lng: 24.9384
},
location: {},
onPositionChanged: () => {}
};
constructor(props) {
super(props); …Run Code Online (Sandbox Code Playgroud) TL;DR:我正在尝试使用新的react-hooksapi,但是在调用setState挂钩时我不断收到 Invariant Violation 错误,但它一直失败。
import React, { useState } from 'react';
// type State = {
// heading: string;
// }
const Text = () => {
const initialState = 'Heading'.toUpperCase();
const [heading, setHeading] = useState(initialState);
return (
<header>
<h1>
{setHeading('Brussels')};
{heading}
</h1>
</header>
);
};
export default Text;
Run Code Online (Sandbox Code Playgroud) 当尝试运行以下命令时:
brew tap wix/brew
brew install applesimutils
Run Code Online (Sandbox Code Playgroud)
我的homebrew 失败如下:
Warning: Some installed formulae are not readable:
applesimutils: /usr/local/Homebrew/Library/Taps/wix/homebrew-brew/applesimutils.rb:4: syntax error, unexpected <<, expecting keyword_end
<<<<<<< HEAD
^
/usr/local/Homebrew/Library/Taps/wix/homebrew-brew/applesimutils.rb:17: syntax error, unexpected ===, expecting keyword_end
=======
^
/usr/local/Homebrew/Library/Taps/wix/homebrew-brew/applesimutils.rb:23: syntax error, unexpected >>, expecting keyword_end
>>>>>>> Detox Instruments 1.10.10110
^
/usr/local/Homebrew/Library/Taps/wix/homebrew-brew/applesimutils.rb:23: unexpected fraction part after numeric literal
>>>>>>> Detox Instruments 1.10.10110
Run Code Online (Sandbox Code Playgroud)
我正在奔跑
Environment:
OS: macOS 10.14.5
Node: 10.15.3
Yarn: 1.16.0
npm: 6.4.1
Watchman: 4.9.0
Xcode: Xcode 10.2.1 Build version 10E1001
Android …Run Code Online (Sandbox Code Playgroud) 我正在尝试将根目录中的静态 JSON 文件解析为已经预定义的对象,但我对如何让对象“读取”JSON 文件中的每个属性并将其显示为自己的属性感到困惑。我希望我不会让这更令人困惑它是什么?
我的一些代码:
class PostsController < ApplicationController
# before_action :set_post, except: [:index, :show]
# @@posts = File.read('app/assets/javascripts/flickr_feed.json')
# @posts = JSON.parse(string)
# GET /posts
# GET /posts.json
def index
@posts = Post.all
respond_to do |format|
format.html
format.json { render json: @@posts }
# format.json { render json: @@posts }
end
end
# GET /post/1
# GET /post/1.json
def show
@post = @post.assign_attributes JSON.parse(File.read('app/assets/javascripts/flickr_feed.json'))
respond_to do |format|
format.html
format.json { render json: @post }
end
end
...
Run Code Online (Sandbox Code Playgroud)
如果我去localhost:3000/posts.json …
我正在将我的 React 应用程序更新为react-16,但我的所有测试都停止了。我已经升级enzyme,jest-enzyme,react-dom,安装enzyme-adapter,创造了setupTest.ts酶的文件,更新了我的jestconfig.js文件,但我仍然得到错误。如果有人知道可能会出什么问题。
执行时没有依赖警告(有关反应|测试) npm ls
这是我的jestconfig
{
"moduleDirectories": [
"node_modules",
"src"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"moduleNameMapper": {
"\\.(css|scss)$": "identity-obj-proxy"
},
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testResultsProcessor": "<rootDir>/node_modules/ts-jest/coverageprocessor.js",
"snapshotSerializers": [
"enzyme-to-json"
],
"setupTestFrameworkScriptFile":"<rootDir>/config/setupTests.ts",
"coveragePathIgnorePatterns": ["node_modules", "__tests__"],
"testRegex": "__tests__/.*\\.test\\.(ts|tsx|js)$",
"collectCoverageFrom": ["src/**/*.{ts,tsx}"],
...rest of code
Run Code Online (Sandbox Code Playgroud)
src/setupTests.ts
import 'raf/polyfill'; // <= this removes the requestAnimationFrame warning error
import * as Enzyme from 'enzyme';
import * …Run Code Online (Sandbox Code Playgroud) reactjs ×7
jestjs ×4
enzyme ×1
flickr ×1
formik ×1
google-maps ×1
homebrew ×1
javascript ×1
json ×1
material-ui ×1
react-16 ×1
react-hooks ×1
redux ×1
ruby ×1
schema ×1
testing ×1
typescript ×1
validation ×1
yup ×1