标题几乎解释了我所面临的问题.我正在尝试测试React具有某种状态的组件,并尝试将我的商店提供给组件以获得它所需的内容.当我使用Jest运行组件的测试时,我收到以下错误:
ReferenceError: regeneratorRuntime is not defined
我已经通过了一些读数确定,这是造成babel-polyfill或者regenerator-runtime没有被正确适用于玩笑.但是,我已经尝试安装这两个软件包并重新运行而不会改变结果.在阅读了Jest Github问题页面(删除自动包含babel-polyfill#2755)之后,我发现babel-polyfillJest自版本19以来并未自动包含.我手动安装该软件包应该已经解决了问题,但它确实不.我已经包含了一些我认为相关的文件
.babelrc:
{
"presets": ["es2015", "react", "stage-2"],
"env": {
"development": {
"plugins": [
["react-transform", {
"transforms": [{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
}]
}]
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
jest.config:
{
"transform": {
"^.+\\.(js|jsx)$": "<rootDir>/node_modules/webpack-babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/jest-vue-preprocessor",
".*": "babel-jest"
},
"moduleNameMapper": {
"\\.(jpg|jpeg|css|scss|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__tests__/__mocks__/fileMock.js",
".*\\.(vue)$": "vue/dist/vue.js"
},
"testPathIgnorePatterns": ["type_parser.spec.js",
"<rootDir>/__tests__/__mocks__/",
"__tests__/unit/core/util/type_parser.js",
"__tests__/GitlabLoader.test.js"
]
}
Run Code Online (Sandbox Code Playgroud)
package.json:
{
"name": "my_project",
"version": "0.2.0", …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用来为我的React应用程序运行测试Jest,但是由于错误提示说这require.context不是函数,所以测试一直失败。我正在寻找该功能的替代品,而该功能Jest将不会停止。我试图动态地require修改某些*.vue文件,Vue.js以便以后在我的应用程序中使用。除此之外,我偶尔还会收到无法识别.vue文件格式的错误,并说无法对其进行解析。这是有问题的代码:
function inject(comp) {
comp.methods = Object.assign({}, comp.methods, stub.methods);
return comp;
}
let req = require.context('./', false, /\.vue$/);
components.forEach(function (component) {
try {
let filePath = __dirname + "\\" + component + '.vue';
let injected = inject(req(filePath));
Vue.component(getComponentName(component), injected);
let appComponent = {
name: injected.name,
props: {
autocompletion: {
metadata: getComponentName('template'),
score: xTemplatesScore,
attributes: injected.props || []
}
}
};
appComponents.push(appComponent);
} catch (err) {
console.log(err); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Mocha.js+JSDOM框架运行测试,但无法Mocha启动。这是在React使用Vue.js库测试应用程序的过程中。我不断收到以下错误:
var req = require.context('./', false, /\.vue$/);
TypeError: require.context is not a function
Run Code Online (Sandbox Code Playgroud)
有问题的代码是:
let req = require.context('./', false, /\.vue$/);
components.forEach(function (component) {
try {
let filePath = './' + component + '.vue';
let injected = inject(req(filePath));
Vue.component(getComponentName(component), injected);
let appComponent = {
name: injected.name,
props: {
autocompletion: {
metadata: getComponentName('template'),
score: xTemplatesScore,
attributes: injected.props || []
}
}
};
appComponents.push(appComponent);
} catch (err) {
console.log(err);
console.error('Vue file was not …Run Code Online (Sandbox Code Playgroud) 我正在尝试将动态创建的动态创建添加div到另一个动态创建div,但我在Chromium JavaScript控制台中不断收到错误,上面写着"无法调用appendChild未定义的方法.我不知道为什么会发生这种情况.这是我的代码用过的:
for(var i=3; i < 8; i++)
{
var parent_div = document.createElement('div');
parent_div.setAttribute('class',"bottom_block left");
document.body.appendChild(parent_div); //Append parent_div to body. This works fine
var child_div = document.createElement('div');
child_div.setAttribute('class', "content SA");
child_div.setAttribute('id', "SA"+i);
document.parent_div.appendChild(child_div); // This is
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试为基于 Flask 的网站上的某些元素设置样式,但由于某种原因,我的 css 文件从未加载过。
不过情况很特殊。layout.html使用 path调用时,文件将正常加载/static/css/,但由于某种原因,页面/css/第二次截断路径并生成404错误。
这是我的 Flask 项目的结构:
Directory Structure:
+app
+static
+css
style-large.css
style.css
style-xlarge.css
+templates
index.html
layout.html
Run Code Online (Sandbox Code Playgroud)
片段layout.html:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block doc_title %} {% endblock %}</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]-->
<script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/skel.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/skel-layers.min.js') }}"></script>
<script src="{{ url_for('static', …Run Code Online (Sandbox Code Playgroud) 我想创建一个叫做Deck类的类Cards.但是,每当我试图看到我放入我的内容时Deck,我都会收到错误消息Segmentation fault (core dumped).我怎样才能解决这个问题?我从其他问题中读到我的程序可能正在尝试访问尚未分配的内存,但我不知道发生了什么.这是我写的代码:
加入deck.h:
#ifndef DECK_H
#define DECK_H
#include <vector>
#include "card.h"
class Deck
{
friend ostream &operator<<(ostream &, Deck &);
public:
Deck();
void shuffle();
private:
vector<Card> myDeck;
};
#endif
Run Code Online (Sandbox Code Playgroud)
Deck.cpp
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include "deck.h"
#include "card.h"
Deck::Deck()
{
for(int i = 1; i <= 4; i++)
{
for(int j = 1; j <= 13; j++)
{
Card myCard(j,i);
myDeck.push_back(myCard);
}
}
}
void Deck::shuffle() …Run Code Online (Sandbox Code Playgroud) 我编写了一个自定义类来存储图像,并最终基于这些图像计算校准,但是在存储图像的方式上遇到了问题。我有两个重载函数可以执行此操作,一个函数使用读取文件中的图像,另一个函数cv::imread使用Snapshot用于保存数据的中间数据结构。使用函数的cv::imread效果很好,但是使用自定义数据结构的函数却不能。我现在尝试存储三个图像,问题是当我将图像推入矢量时,第二个图像的数据被复制到第一个图像中。
这是工作功能:
bool CalibClass::AddImage(const std::string& snapshotPath) {
cv::Mat img = cv::imread(snapshotPath);
// _snapshots is a private member declared as a std::vector<cv::Mat>
_snapshots.push_back(img);
return true;
}
Run Code Online (Sandbox Code Playgroud)
这是不起作用的功能:
bool CalibClass::AddImage(const ImageSet& snapshot) {
RGBImage *rgb_image_ptr = snapshot.GetRGBImage();
std::vector<unsigned char> img_data(rgb_image_ptr->GetData());
cv::Mat img(rgb_image_ptr->GetHeight(), rgb_image_ptr->GetWidth(), CV_8UC3, img_data.data());
_snapshots.push_back(img);
return true;
}
Run Code Online (Sandbox Code Playgroud)
在ImageSet类存储图像作为std::unique_ptr<RGBImage>。在RGBImage类存储的图像数据作为std::vector<unsigned char>。
这是将图像从中加载到类中的方式main:
cv::Mat img1 = cv::imread("img1.png");
cv::Mat img2 = cv::imread("img2.png");
cv::Mat img3 = cv::imread("img3.png");
int length …Run Code Online (Sandbox Code Playgroud)