在我的Jest单元测试中,我正在使用ColorPicker渲染一个组件.该ColorPicker
组件创建一个canvas对象和2d上下文,但返回'undefined'
会引发错误"Cannot set property 'fillStyle' of undefined"
if (typeof document == 'undefined') return null; // Dont Render On Server
var canvas = document.createElement('canvas');
canvas.width = canvas.height = size * 2;
var ctx = canvas.getContext('2d'); // returns 'undefined'
ctx.fillStyle = c1; // "Cannot set property 'fillStyle' of undefined"
Run Code Online (Sandbox Code Playgroud)
我遇到了麻烦,弄清楚为什么我无法获得二维背景.也许我的测试配置存在问题?
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react",
"<rootDir>/node_modules/react-dom",
"<rootDir>/node_modules/react-addons-test-utils",
"<rootDir>/node_modules/react-tools"
],
"moduleFileExtensions": [
"jsx",
"js",
"json",
"es6"
],
"testFileExtensions": [
"jsx"
],
"collectCoverage": true …
Run Code Online (Sandbox Code Playgroud) 尝试将一些代码附加到div层后,我收到以下错误,不知道为什么.
未捕获的异常:[Exception ..."无法转换JavaScript参数arg 0 [nsIDOMDocumentFragment.appendChild]"nsresult:"0x80570009(NS_ERROR_XPC_BAD_CONVERT_JS)"location:"JS frame :: http://code.jquery.com/jquery-latest .min.js :: anonymous :: line 113"data:no]
下面是导致错误的代码.我知道有一些过多的代码,但我这样做,所以很容易为未来的功能构建.只是寻找任何错误的建议?谢谢!:)
function catSelect(itm){
//params for query
var params = {
category: itm
};
var cmd = jQuery.param(params);
$.ajax({
async: false,
type: "POST",
cache: false,
url: "views/gallery.php",
data: cmd,
dataType: "json",
success: function(resp){
if(resp.status == "ok") {
$('#project').empty();
//alert(resp.projects[0]);alert(resp.files[0]); alert(resp.titles[0]);
var check = 0;
var projGallery = new Array();
for(var i in resp.projects){
if(check!=resp.projects[i] || check == 0){
projGallery[i] ='<a class="group" title="'+resp.titles[i]+'" href="images/gallery/"'+resp.files[i]+'" rel="'+resp.projects[i]+'" ><img class="group" alt="" …
Run Code Online (Sandbox Code Playgroud) 我正在运行带有 multipass hyperkit 的 Ubuntu VM,并且运行 microk8s。在 VM 内,所有内容均可通过 skaffold/kubectl 端口转发进行检查和使用。例如:
\n$ multipass list\nName State IPv4 Image\nmicrok8s-vm Running 192.168.64.2 Ubuntu 20.04 LTS\n 10.0.1.1\n 172.17.0.1\n 10.1.254.64\n
Run Code Online (Sandbox Code Playgroud)\nPort forwarding service/my-app in namespace default, remote port 80 -> 127.0.0.1:4503
在虚拟机内:curl localhost:4503
\xe2\x9c\x85
来自主持人:curl 192.168.64.2:4503
我知道虚拟机可以通过端口 80 访问,因为curl 192.168.64.2
返回默认的 ngnix 未找到页面。FWIW 我从未安装过 ngnix 并且该服务似乎没有运行/无法将其关闭。
我已经在这个问题上呆了一天了,我被难住了。我什至尝试了 Vbox 驱动程序并手动配置了桥接适配器。我什至创建了自己的适配器......
\n$ multipass exec -- microk8s-vm sudo bash -c "cat > /etc/netplan/60-bridge.yaml" <<EOF\nnetwork:\n ethernets:\n enp0s8: # …
Run Code Online (Sandbox Code Playgroud) 我有一个mod_rewrite我想在我的Mac上本地使用但是当我将配置改为我的目录标签时,我得到403 Forbidden错误.我已经尝试了所有其他解决方案,但没有运气.
也许有人会看到我不是......
这是代码:
httpd.conf文件
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
<Directory "/Library/WebServer/Documents/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)
这被myusername.conf覆盖
<Directory /Users/adrianmaurer/Sites/www>
Options Indexes MultiViews FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)
虚拟主机文件httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /Users/adrianmaurer/Sites/www
ServerName myserver.dev
</VirtualHost>
Run Code Online (Sandbox Code Playgroud) 我正在尝试获取测试的覆盖率报告,但所有文件的覆盖率输出始终在一行上,显示带有文件路径的require.例如...
然而,测试运行良好.这是一个反应项目,因此我必须在文件和预处理器中包含一些额外的路径以使测试运行.
我不确定我的业力配置是否有问题?这就是我的配置目前的样子......
/* global module */
module.exports = function (config) {
'use strict';
config.set({
autoWatch: true,
singleRun: true,
frameworks: ['browserify', 'jasmine'],
files: [
'node_modules/karma-babel-preprocessor/node_modules/babel-core/browser-polyfill.js',
'node_modules/react/react.js',
'src/**/*.jsx',
'src/**/!(*spec).js'
],
browsers: ['PhantomJS'],
preprocessors: {
'node_modules/react/react.js': ['browserify', 'sourcemap'],
'src/**/*.jsx': ['browserify', 'sourcemap', 'coverage'],
'src/**/!(*spec).js': ['browserify', 'sourcemap', 'coverage'],
},
browserify: {
debug: true,
transform: [ 'babelify' ]
},
reporters: ['progress', 'coverage'],
coverageReporter: {
instrumenters: {isparta: require('isparta')},
instrumenter: {
'src/**/*.js': 'isparta',
'src/**/*.jsx': 'isparta'
},
reporters: [
{
type: 'text-summary',
subdir: normalizationBrowserName
},
{
type: 'lcov', …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用正则表达式来验证值是否以特定方式格式化Lastname, Firstname
(请参阅我进行格式断言的注释)。
我编写的测试使用 MockMvcResultMatchers。我找不到这个库的好的文档,我只能看到 API。因此,目前,我正在构建一个 ResultMatcher,jsonpath
假设它将对模式匹配进行断言并返回一个布尔值。但它只返回我的值$.name
。
不确定我做错了什么。我粘贴了一个测试版本来演示我正在尝试做的事情。
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.regex.Pattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class SomeEntityControllerTests {
@Autowired
private MockMvc mockMvc;
private Pattern name = Pattern.compile("^[A-Za-z0-9_']+\\s?,\\s?[A-Za-z0-9_']+$");
@Test
public void getSomeEntityShouldReturnOkWithProperlyFormatted() throws Exception {
this.mockMvc.perform(get("/api/v1/someEntity/132")).andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.name").exists());
.andExpect(jsonPath("$.name", matches(name))); // <-- FORMAT ASSERTION NOT WORKING. Only getting the string value …
Run Code Online (Sandbox Code Playgroud) 尝试在服务器上运行应用程序时,我的集成机器人抱怨...
xcodebuild: error: No destinations were specified with the -destination flag which were valid for the specified scheme 'MyScheme'.
不确定如何处理此错误?
在崩溃之前,它会针对不同的设备进行大量搜索......
2014-05-21 14:14:22.631 xcodebuild[49977:100b] [MT] DVTDeviceSearch: Searching for device with type 'iOS Simulator', options: {
OS = "7.1";
name = iPad;
}, genericOnly: NO allowMultiple:NO timeout:0.000000
2014-05-21 14:14:23.134 xcodebuild[49977:100b] [MT] DVTDeviceSearch: Search found devices: (
"<DVTiPhoneSimulator: 0x7ff6fdb9a230> {\n\t\tsessionActive: NO\n\t\tlaunchService: (null)\n\t\tlaunchSucceeded: NO\n\t\tcurrentSimulatorSession: (null)\n\t\tdidExitRecursionGuard: NO\n\t\tdeviceInfo: <DeviceInfo iPad>\n\t\tsimulatedSystemRoot: <DTiPhoneSimulatorSystemRoot 0x7ff6fdb8e6f0> path=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk version=7.1 name=Simulator - iOS 7.1\n\t\tsimulatedDeviceFamily: 2\n\t\tsupportedDeviceFamilies: (\n 1,\n 2\n)\n\t\t}"
)
检查服务器xcode我可以看到安装了6.1和7.0模拟器.
它也可以从xcode运行良好.
invoke local
无服务器处理请求负载的方式与部署到 AWS 时的行为似乎有所不同。
预期的行为是您将从请求正文中提取有效负载,如下所示......
func Handler(ctx context.Context, request events.APIGatewayProxyRequest)
Run Code Online (Sandbox Code Playgroud)
然后将其解组为您的数据类型,如下所示......
type SearchQuery struct {
Caller string `json:"caller"`
Value string `json:"value"`
}
Run Code Online (Sandbox Code Playgroud)
err := json.Unmarshal([]byte(request.Body), &searchQuery)
Run Code Online (Sandbox Code Playgroud)
但是,当使用该--data
标志在本地调用该函数时,有效负载不在request.Body
.
events.APIGatewayProxyRequest) {
Resource: (string) "",
Path: (string) "",
HTTPMethod: (string) "",
Headers: (map[string]string) <nil>,
MultiValueHeaders: (map[string][]string) <nil>,
QueryStringParameters: (map[string]string) <nil>,
MultiValueQueryStringParameters: (map[string][]string) <nil>,
PathParameters: (map[string]string) <nil>,
StageVariables: (map[string]string) <nil>,
RequestContext: (events.APIGatewayProxyRequestContext) {
AccountID: (string) "",
ResourceID: (string) "",
Stage: (string) "",
RequestID: (string) "",
Identity: (events.APIGatewayRequestIdentity) {
CognitoIdentityPoolID: …
Run Code Online (Sandbox Code Playgroud) reactjs ×2
ajax ×1
apache ×1
append ×1
aws-lambda ×1
browserify ×1
ecmascript-6 ×1
go ×1
html5-canvas ×1
istanbul ×1
javascript ×1
jestjs ×1
jquery ×1
jsdom ×1
kubernetes ×1
macos ×1
microk8s ×1
multipass ×1
parsing ×1
regex ×1
serverless ×1
skaffold ×1
spring-boot ×1
unit-testing ×1
xcode ×1
xcode-bots ×1
xcodebuild ×1