我正在尝试使用酶来测试React Native FlatList。我想检查列表到达末尾时是否调用了正确的函数:
import { listIsAtTheEnd } from "./actions";
import { mount } from "enzyme";
jest.mock("./actions");
describe("Main page", () => {
if("Calls listIsAtTheEnd when FlatList reaches the end", () => {
var app = mount(<App />);
var container = app.find("FlatListContainer");
var fList = container.childAt(0);
fList.instance().scrollToEnd();
expect(listIsAtTheEnd.mock.calls).toHaveLength(1)
})
})
Run Code Online (Sandbox Code Playgroud)
但这就是我得到的:
TypeError: this._scrollRef.scrollTo is not a function
at VirtualizedList.scrollToEnd (node_modules/react-native/Libraries/Lists/VirtualizedList.js:219:17)
at FlatList.scrollToEnd (node_modules/react-native/Libraries/Lists/FlatList.js:544:141)
at Object.<anonymous> (src/components/forumPage/__tests__/forumPageTests.js:81:21)
at tryCallTwo (node_modules/promise/lib/core.js:45:5)
at doResolve (node_modules/promise/lib/core.js:200:13)
at new Promise (node_modules/promise/lib/core.js:66:3)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?什么是正确的测试方法?
我正在尝试使用 Glide 加载图像:
case "image":
Log.d("TRecyViewAdapter", "Got Image");
ImageView imageView = new ImageView(context);
imageView.setLayoutParams(new GridLayoutManager.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT
));
contents.addView(imageView);
Glide.with(context).load(part.getContent()).into(imageView);
break;
Run Code Online (Sandbox Code Playgroud)
它什么都不显示。
但是,如果我将最后一行更改为毕加索:
Picasso.with(context).load(part.getContent()).into(imageView);
Run Code Online (Sandbox Code Playgroud)
正如我所期望的那样,图像以全尺寸加载。
还。如果我使用带有占位符的 Glide:
Glide.with(context).load(part.getContent()).placeholder(R.mipmap.def_avatar).into(imageView);
Run Code Online (Sandbox Code Playgroud)
它加载图像但尺寸非常小(R.mipmap.def_avatar 的大小)
我希望能够加载实际大小的图像而不必指定占位符(它是一个动态视图,它应该显示许多不同大小的不同图像等等)
我想使用 Glide 而不是 Picasso 因为我想要支持动画 gif。
我正在尝试使用JavaScript复制PHP字符串加密.这是PHP代码:
<?php
$iv = "1234567890123456";
$key = "aaaaaaaaaaaaaaaa";
$input = "texttexttexttext";
$encrypted = openssl_encrypt($input, "AES-256-CBC", $key, 0, $iv);
echo $encrypted;
// "ZwY1i+vqP3acszeDiscCTx/R4a6d2AtkcInmN9OTCNE="
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在JavaScript中复制它时,它会提供不同的密文:
var aesjs = require("aes-js");
var base64 = require("js-base64");
var iv = aesjs.utils.utf8.toBytes("1234567890123456");
var key = aesjs.utils.utf8.toBytes("aaaaaaaaaaaaaaaa");
var text = aesjs.utils.utf8.toBytes("texttexttexttext");
var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);
var encryptedBytes = aesCbc.encrypt(text);
var b64encoded = base64.Base64.encode(encryptedBytes);
console.log(b64encoded);
// "MTcyLDIsNjAsMTU5LDcxLDEwLDE4Myw4LDE…wyMTIsMjIyLDk3LDEyNCw1MywxNzIsMjIy"
Run Code Online (Sandbox Code Playgroud)
我不知道如何让它给出相同的输出.有任何想法吗?
我有一个包含一些python文件的文件夹:
modules
|--> __init__.py
|--> car.py
|--> plane.py
|--> ship.py
|--> etc...
Run Code Online (Sandbox Code Playgroud)
每个文件都包含以下内容:
car.py
NAME = "car_name"
def mainloop(*args):
...
return whatever
Run Code Online (Sandbox Code Playgroud)
plane.py
NAME = "some_different_name"
def mainloop(*args):
...
return whatever
Run Code Online (Sandbox Code Playgroud)
等等...
我想从我的父目录动态导入它们作为这样的字典:
from modules import modules
print(modules)
{
"car_name": <function mainloop at ...>,
"some_different_name": <function mainloop at ...>,
etc..
}
Run Code Online (Sandbox Code Playgroud)
我不知道文件夹或文件名上会有多少文件.我该怎么做?
javascript ×2
aes ×1
android ×1
encryption ×1
enzyme ×1
jest ×1
php ×1
picasso ×1
python ×1
react-native ×1