TLDR:如何告诉我的Enzyme / Jest测试应该像在iOS上一样运行测试?我想测试平台的特定行为。
我正在构建一个自定义状态栏组件,如果该组件在iOS上运行时会增加20像素的高度,以防止我的内容与状态栏重叠。(是的,我知道React-Navigation具有SafeAreaView,但这仅适用于iPhone X,不适用于iPad。)
这是我的组件:
import React from "react";
import { StatusBar as ReactNativeStatusBar, View } from "react-native";
import styles from "./styles";
const StatusBar = ({ props }) => (
<View style={styles.container}>
<ReactNativeStatusBar {...props} />
</View>
);
export default StatusBar;
Run Code Online (Sandbox Code Playgroud)
Here is the styles.js
file:
import { StyleSheet, Platform } from "react-native";
const height = Platform.OS === "ios" ? 20 : 0;
const styles = StyleSheet.create({
container: {
height: height
}
});
export default …
Run Code Online (Sandbox Code Playgroud) 我有一个可滚动的元素。我还有一个滚动到特定位置的功能。我想在 scrollTo 完成后调用一个函数。
var x = document.querySelector('.container');
$scope.scrollTo = function() {
x.scrollTo({
top: 300 ,
behavior: 'smooth'
});
};
// do something when scrollTo is finished
Run Code Online (Sandbox Code Playgroud) I have implemented model validation in some of my APIs, but I was wondering if it is possible to do some validation using attributes on simple parameters, like:
[HttpGet("test/{type}")]
public ActionResult GetSomeData([Range(0,2)]byte type)
{
if (!ModelState.IsValid)
{
// isValid is always TRUE
}
...
}
Run Code Online (Sandbox Code Playgroud)
When you call /controller/test/4, IsValid is always TRUE.
Is there a clean way to do that?
Thanks!
在 CNN 中,卷积操作在输入矩阵上“卷积”一个内核矩阵。现在,我知道全连接层如何利用梯度下降和反向传播来训练。但是核矩阵是如何随时间变化的呢?
在 Keras 文档中,有多种初始化内核矩阵的方法,如此处所述。但是,我很想知道它是如何训练的?如果它也使用反向传播,那么有没有详细描述训练过程的论文?
这篇文章也提出了一个类似的问题,但没有答案。
我可以引用一个共同的制定者_setTerm
在性write
访问,而无需编写单独的setter方法_setTerm1
,_setTerm2
,_setTerm3
?
TAdder = class(TCalculatorComponent)
private
_terms: array[1..10] of OleVariant;
procedure _setTerm(const i: Integer; const Value: OleVariant);
procedure _setTerm1(const Value: OleVariant);
procedure _setTerm2(const Value: OleVariant);
procedure _setTerm3(const Value: OleVariant);
.......
public
constructor Create(AOwner: TComponent); override;
property Term1: OleVariant read _terms[1] write _setTerm1;
property Term2: OleVariant read _terms[2] write _setTerm2;
property Term3: OleVariant read _terms[3] write _setTerm3;
.......
end;
implementation
procedure TAdder._setTerm(const i: Integer; const Value: OleVariant);
begin
_terms[i] := TVarConv.NullableFloat(Value);
_calculate(); …
Run Code Online (Sandbox Code Playgroud) 我正在使用Saxon处理器来执行验证.
包含所有函数定义的文件如下:
default-definition.txt:
declare variable $a external;
declare variable $b external;
declare variable $c external;
declare function iaf:sum(
$params as item()*
) as item()+ {
let $facts := if (empty($params)) then (0) else one-or-more($params)
let $values := for $i in $facts return (iaf:splitValueThreshold($i)[1])
let $thresholds := for $i in $facts return (iaf:splitValueThreshold($i)[2])
let $sumValues := sum($values)
let $sumThresholds := sum($thresholds)
let $output := iaf:joinValueThreshold($sumValues, $sumThresholds)
return ($output)
};
declare function iaf:numeric-equal(
$paramA as item(), $paramB as item() …
Run Code Online (Sandbox Code Playgroud) 我正在与我的eslint一起解决一个小问题,它似乎在大多数情况下工作正常,但有些情况下它与React代码不起作用.
我们以此代码为例:
const cellPLay = (name, src) => (
<Table.Cell>
<Modal trigger={<Button icon><Icon name="video play" size="large" /></Button>}>
<Modal.Header>
{name}
</Modal.Header>
<Modal.Content image>
<Modal.Description>
<video src={src} controls style={{ width: 910 }} />
</Modal.Description>
</Modal.Content>
</Modal>
</Table.Cell>
);
Run Code Online (Sandbox Code Playgroud)
给出这样的错误:
/my-path/MyFile.js:18:7:预期缩进8个空格字符,但找到6. [Error/react/jsx-indent]
出于某种原因,eslint认为Modal.Content应该在Modal.Header之后缩进,但是即使我修复了所有缩进,它也要求它说某些结束标记的缩进是错误的:
预期结束标记以匹配开口缩进
我的eslint配置文件:
{
"extends": "./my-eslint/index.js"
}
Run Code Online (Sandbox Code Playgroud)
实际的eslint代码:
module.exports = {
extends: require.resolve('eslint-config-airbnb'),
env: {
browser: true,
jest: true,
es6: true,
},
parserOptions: {
ecmaVersion: 8,
sourceType: 'module',
ecmaFeatures: {
jsx: …
Run Code Online (Sandbox Code Playgroud) 我已经安装了最新版本"rxjs": "6.2.2",
和"redux-observable": "1.0.0",
。
我有预先提交的钩子,可以进行eslint检查。
安装开始后,抛出此错误:
C:\XXX\node_modules\any-observable\register.js:29
throw new Error('Cannot find any-observable implementation nor' +
^
Error: Cannot find any-observable implementation nor
global.Observable. You must install polyfill or call
require("any-observable/register") with your preferred implementation,
e.g. require("any-observable/register")('rxjs') on application load
prior to any require("any-observable").
at loadImplementation (C:\XXX\node_modules\any-observable\register.js:29:9)
at register (C:\XXX\node_modules\any-observable\loader.js:32:18)
at Object.<anonymous> (C:\XXX\node_modules\any-observable\index.js:2:39)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
husky > pre-commit hook …
Run Code Online (Sandbox Code Playgroud) 我想创建将包含以下扩展方法的 .Net Core 类库:
public static class MyServiceExtensions
{
public static IServiceCollection AddMyService<TUserDto, TUserDtoKey, TUser, TUserKey>(this IServiceCollection services)
where TUserDto : UserDto<TUserDtoKey>
where TUser : User<TUserKey>
{
services.AddAutoMapper(config =>
{
config.AddProfile<UserMappingProfile<TUserDto, TUserDtoKey, TUser, TUserKey>>();
});
return services;
}
}
Run Code Online (Sandbox Code Playgroud)
我有以下 Automapper 配置文件:
public class UserMappingProfile<TUserDto, TUserDtoKey, TUser, TUserKey> : Profile
where TUserDto : UserDto<TUserDtoKey>
where TUser : User<TUserKey>
{
public UserMappingProfile()
{
CreateMap<TUserDto, TUser>(MemberList.Destination)
.ForMember(x => x.Id, opts => opts.MapFrom(x => x.UserId));
CreateMap<TUser, TUserDto > (MemberList.Source)
.ForMember(x => x.UserId, opts …
Run Code Online (Sandbox Code Playgroud) 我的代码中有一个函数,如下所示:
bool foo(ObjectType& object){
//code
const float result = object.float_data + object.bool_data * integer_data;
//code
}
Run Code Online (Sandbox Code Playgroud)
在寻找错误时,我发现result
有时会有不正确的值,原因是有时bool
*integer
被计算为255*integer
而不是1*integer
。
C++ 说在整数上下文中bool
会转换为零或一,所以我不明白这一点。我与bool
代码中的其他部分相乘,效果很好。这也是随机的:有时会转换为1
,有时会转换为255
。调试器还分别显示true
或255
。当这个错误发生时,它总是发生在该执行中。重新编译代码没有任何效果,它仍然随机发生。
asp.net-core ×2
c# ×2
eslint ×2
.net-core ×1
angularjs ×1
arrays ×1
automapper ×1
c++ ×1
c++17 ×1
convolution ×1
delphi ×1
enzyme ×1
gcc ×1
java ×1
javascript ×1
jestjs ×1
keras ×1
platform ×1
react-native ×1
reactjs ×1
rxjs ×1
saxon ×1
setter ×1
validation ×1
xbrl ×1
xml ×1
xquery ×1