如何过滤getByLabelText查询,如果它抛出类型错误:TestingLibraryElementError: Found multiple elements with the text of: /to/i,我有以下 HTML 结构,其中有一些嵌套标签:
<div class="ant-row ant-form-item ant-radio-group-cards" style="row-gap: 0px;">
<div class="ant-col ant-form-item-label">
<!-- <label> with "To" text -->
<label for="transferFunds_to" class="ant-form-item-required" title="To">To</label>
</div>
<div class="ant-col ant-form-item-control">
<div class="ant-form-item-control-input">
<div class="ant-form-item-control-input-content">
<!-- Other <label> with "To" text here -->
<label class="ant-radio-button-wrapper">
<span class="ant-radio-button"><input id="transferFunds_to" type="radio" class="ant-radio-button-input" value="" /><span class="ant-radio-button-inner"></span></span>
<span>
<li class="ant-list-item">
<div class="ant-list-item-meta">
<div class="ant-list-item-meta-avatar">
<svg width="1em" height="1em" viewBox="0 0 16 16" fill="none" style="font-size: 48px;"></svg> …Run Code Online (Sandbox Code Playgroud) javascript unit-testing reactjs jestjs react-testing-library
我在一个类中有一个方法,我想接受任何对象作为参数,但我不想使用any,为此我使用 ageneric和 extend object。
class MyClass {
saveObject<T extends object>(object: T | null) {}
}
Run Code Online (Sandbox Code Playgroud)
有了这个实现,@typescript-eslint/ban-typesrule 会报以下错误:
Don't use 'object' as a type. The 'object' type is currently hard to use see this issue(https://github.com/microsoft/TypeScript/issues/21732)). Consider using 'Record<string, unknown>' instead, as it allows you to more easily inspect and use the keys.ok,那么我会听 Eslint 并做以下实现:
class MyClass {
saveObject<T extends Record<string, unknown>>(object: T | null) {}
}
Run Code Online (Sandbox Code Playgroud)
通过上面的实现,Eslint 错误消失了,所以我尝试使用随机对象执行该方法:
anyOtherMethodInMyCode(payment: IPaymentModel …Run Code Online (Sandbox Code Playgroud) 我想在 Django 管理中上传多个文件,而不必放置多个 FileField 字段。用户能够以简单的方式管理文件;删除或更改每个上传的文件,但一次上传多个。
我认为可行的解决方案是使用多个文件字段,但问题是,我不知道用户将上传多少文件
def case_upload_location(instance, filename):
case_name = instance.name.lower().replace(" ", "-")
file_name = filename.lower().replace(" ", "-")
return "casos/{}/{}".format(case_name, file_name)
class Case(models.Model):
name = models.CharField(max_length=250)
observations = models.TextField(null = True, blank = True)
number_folder = models.CharField('Folder', max_length=250)
file1 = models.FileField('file 1', upload_to=case_upload_location, null = True, blank = True)
file2 = models.FileField('file 2', upload_to=case_upload_location, null = True, blank = True)
file3 = models.FileField('file 3', upload_to=case_upload_location, null = True, blank = True)
file4 = models.FileField('file 4', upload_to=case_upload_location, null = True, …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个验证输入强度的密码字段,在另一个答案中我发现regex我可以使用它来验证输入是否满足特定条件,这种方法的问题是它只为每个输入抛出一条错误消息的验证。
password: yup
.string()
.required('Please Enter your password')
.matches(
/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$/,
"Must Contain 8 Characters, One Uppercase, One Lowercase, One Number and one special case Character"
),
Run Code Online (Sandbox Code Playgroud)
我想要的是验证用户输入的每个字符,并在满足每个条件时抛出特定错误,例如,如果用户输入缺少小写字母,它应该抛出错误“必须有小写字母”,如果输入缺少数字,它应该抛出数字“必须有数字”等等。我尝试过使用 match 但这不起作用:
password: yup
.string()
.required('Please Enter your password')
.matches(/^[a-z]+$/, 'One lowercase character')
.matches(/^[A-Z]+$/, 'One uppercase character')
.matches(/^\d+$/, 'One number')
// ... other validation
Run Code Online (Sandbox Code Playgroud) 我创建了一个新的 Next 项目,我想根据NODE_ENV变量来管理应用程序行为。应用程序必须加载位于不同 .env 文件中的不同变量。耶。如果我加载NODE_ENV=development,应用程序应该加载位于.env.development文件中的变量。在 Next.js 中最有效和最安全的方法是什么?
在dev脚本中,我传递了环境类型:
"scripts": {
"dev": "cross-env NODE_ENV=development next",
"build": "next build",
"start": "next start",
},
Run Code Online (Sandbox Code Playgroud)
在下一个配置中,我dotenv根据package.jsonNODE_ENV中dev脚本中的变量传递从带有库的正确 .env 文件中加载环境变量。
"scripts": {
"dev": "cross-env NODE_ENV=development next",
"build": "next build",
"start": "next start",
},
Run Code Online (Sandbox Code Playgroud)
TITLE=modo development
Run Code Online (Sandbox Code Playgroud)
const path = require('path');
const withOffline = require('next-offline');
const webpack = require('webpack');
require('dotenv').config({
path: path.resolve(
__dirname,
`.env.${process.env.NODE_ENV}`,
),
});
module.exports = …Run Code Online (Sandbox Code Playgroud) 我有一个电子商务项目,由 3 部分组成, an admin dashboard、 anapi(core)和 a storefront(frontend),dashboard和api将从开源存储库中获取,并将storefront在自己的存储库上从 0 开始开发,现在我的问题是,什么是在 git 上处理这个问题的最佳方法是什么?submodules使用开源存储库和我的前端存储库进行创建,或者fork使用开源存储库进行创建并添加前端。
我想在开源存储库中进行一些更改,但也要使其与原始存储库中可以进行的更改保持同步。
我将使用 docker-compose 来运行服务..
这是我想用作开发电子商务的模板的开源存储库,不同之处在于我想用其他技术来开发店面......
javascript ×2
reactjs ×2
django ×1
django-forms ×1
formik ×1
git ×1
github ×1
jestjs ×1
next.js ×1
node.js ×1
python ×1
typescript ×1
unit-testing ×1
yup ×1