我有这个行动的反应
export function fetchPosts() {
const request = axios.get(`${WORDPRESS_URL}`);
return {
type: FETCH_POSTS,
payload: request
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下如何测试axios?Jest在那里有这个用例的异步代码,他们使用模拟函数,但我不知道我是否可以用axios做到这一点?参考:https://facebook.github.io/jest/docs/tutorial-async.html
到目前为止,我已经做了这个测试,它正在返回正确的类型
it('should dispatch actions with the correct type', () => {
store.dispatch(fetchPosts());
let action = store.getActions();
expect(action[0].type).toBe(FETCH_POSTS);
});
Run Code Online (Sandbox Code Playgroud)
我不知道如何传递模拟数据并测试它返回但是,有没有人有任何想法?
先感谢您
当我运行react-scripts test --env=jsdom它时总是显示:
2018-07-04 09:57 node[61600] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2018-07-04 09:57 node[61600] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2018-07-04 09:57 node[61600] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:167
throw er; // Unhandled 'error' event
^
Error: EMFILE: too many open files, watch
at FSEvent.FSWatcher._handle.onchange (fs.js:1370:28)
Emitted 'error' event at:
at FSEvent.FSWatcher._handle.onchange (fs.js:1376:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! stampling@0.1.0 test: `react-scripts test --env=jsdom`
npm ERR! …Run Code Online (Sandbox Code Playgroud) 我尝试使用反应,react-d3但我一直在收到错误,第一次,我已经使用react v16但它要求React v0.14.9.
所以现在我可以在出现错误之前看到图表.
我用反应d3的这个tuto.
设置后出现错误:
findComponentRoot(..., .0.0.1.0.0.1.0.$/=13.0.$faux-dom-0): Unable to find element. This probably means the DOM was unexpectedly mutated (e.g., by the browser), usually due to forgetting a <tbody> when using tables, nesting tags like <form>, <p>, or <a>, or using non-SVG elements in an <svg> parent. Try inspecting the child nodes of the element with React ID ''.
Run Code Online (Sandbox Code Playgroud)
这听起来像我有一张桌子,但不是,App.js看起来像:
import React, { Component } from 'react';
import './App.css';
import {Chart} …Run Code Online (Sandbox Code Playgroud) 我axios-mock-adapter用来模拟我的API,它可以正常工作,但是在一个模拟中它返回404错误,但我找不到原因。
还有这里与测试沙箱,你可以当我们运行测试看,第二次检查失败,因为axios POST电话已经无法模拟。我已经尝试删除标题部分,但是运行测试时沙箱崩溃了。
import axios from "axios";
import MockAdapter from 'axios-mock-adapter';
import Utils from "../Utils/Utils";
// Global variable for post request with axios
global.users_post = axios.create({
baseURL: "http://localhost:5000/api/",
headers: {'Content-Type': 'application/json'}
});
/* Mockup API */
var userMock = new MockAdapter(users_post);
const user_resp_full = {
data: {
first_name: "Test",
last_name: "Test",
email: "test@gmail.com",
address: "Test",
zipcode: 1010,
city: "Test",
admin: false
}
}
const testAPI = () => {
userMock
.onPost("users", user_resp_full, Utils.getAuth()) …Run Code Online (Sandbox Code Playgroud) 当我尝试使用jest对reactjs执行测试时,它总是返回错误:
我已经正确安装了Jest,我已经尝试删除导入但是下一步会出错.
App.test.js:
import React from 'react';
import {shallow }from 'enzyme';
import renderer from 'react-test-renderer';
import ReactDOM from 'react-dom';
import App from './App.js';
import User from './Modules/User.js';
const user = {
email: "test@gmail.com",
first_name: "test",
last_name: "test"
}
test('Users renders properly', () => {
const wrapper = shallow("<User users={user}/>");
const element = wrapper.find('input');
});
Run Code Online (Sandbox Code Playgroud)
如果它没有说导入错误,当我设置shallow()时它不会识别浅;
随意询问更多细节.
我已经搜索了 1 个小时来了解(并获得可行的来源)调整大小在 CSS(媒体)中发生时如何触发以及由哪个组件触发。我想要的是它在浏览器中的工作方式,调整窗口大小时它的作用。不是代码。
这样做的目的是创建一个序列图来描述调整课程大小所发生的事情。
我发现的只是如何调整大小和其他代码结果,而不是它如何工作的理论点。
感谢您的帮助。
我已经根据这篇文章实现了 createBrowserHisotry如何在 react-router v4 上获取历史记录?,但是它只有在我将配置属性设置为 forceRefresh: true 时才会重定向。如果我不设置任何配置属性,则 url 将更改为推送的 url,但页面不会重定向。为什么?
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./components/App";
import { Router } from 'react-router-dom'
import registerServiceWorker from "./registerServiceWorker";
import history from "./components/common/History";
ReactDOM.render(<Router history={history}><App /></Router>,
document.getElementById('root'));
registerServiceWorker();
Run Code Online (Sandbox Code Playgroud)
import createBrowserHistory from 'history/createBrowserHistory';
// export default createBrowserHistory(); --> This redirects the ### ### URL
// but does not physically redirect
export default createBrowserHistory({
//pass a configuration object here if needed
forceRefresh: …Run Code Online (Sandbox Code Playgroud) 我想从本地获取 json 文件并使用以下命令将其发送到 QML:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
engine.rootContext()->setContextProperty("text_json", "{\"text1\": \"Loading\"}");
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreated,
&app,
[url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},
Qt::QueuedConnection
);
engine.load(url);
return app.exec();
}
Run Code Online (Sandbox Code Playgroud)
但它这么说,QQmlEngine::setContextForObject(): Object already has a QQmlContext但我不明白该默认文件中的任何内容。
从现在起我什么也没发现。
-- 添加了 Main.qml --
import QtQuick 2.15
import QtQuick.Controls 2.15
ApplicationWindow { …Run Code Online (Sandbox Code Playgroud) 我有反应应用程序的问题.我从git克隆它并运行命令npm install和npm start,我收到了这个错误.
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:140:18)
at node.js:1043:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! front-end-react@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the front-end-react@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,它使用区域设置来选择语言和带有翻译的 json,并且我正在制作一个配置器。为此,我需要有一个格式language_COUNTRYNAME类似于en_US.
我在 Locale flutter 类中找到了这个常量列表,并且我想获取 JSON 中的完整列表而不手动复制它,我该怎么做?