我正在用 react-testing-library 测试我的组件,并且测试运行良好。我只是无法摆脱这个警告,fireEvent 应该包装在开箱即用的行为中,但我试图再次包装它,但它没有帮助。
这是我的测试用例。
it.only("should start file upload if file is added to the field", async () => {
jest.useFakeTimers();
const { getByTestId } = wrapper;
const file = new File(["filefilefile"], "videoFile.mxf");
const fileInput = getByTestId("drop-zone").querySelector(
"input[type='file']"
);
fireEvent.change(fileInput, { target: { files: [file] } });
act(() => {
jest.runAllTimers();
});
await wait(() => {
expect(
initialProps.uploadItemVideoFileConnect.calledWith(file, 123)
).toBe(true);
});
});
Run Code Online (Sandbox Code Playgroud)
这是警告
Warning: An update to UploadButtonGridComponent inside a test was not wrapped in act(...).
When testing, code that …Run Code Online (Sandbox Code Playgroud) 我正在测试我的应用程序,需要验证是否使用正确的数据调用了mongoose模式构造函数.
让我说我这样做:
const UserData = new User(user)
console.log(UserData.contructor.args)
Run Code Online (Sandbox Code Playgroud)
我希望user对象的日志.可能数据传递给mongoose模式的构造函数?
有人可以告诉我如何访问它?
这是我试图解决的具体案例.
export const signup = async (req, res, next) => {
try {
//if user object is missing return error
if (!req.body.user)
return next(boom.unauthorized('No user data received.'))
//get user data
const user = req.body.user,
{ auth: { local: { password, password_2 } } } = user
//check if both passwords match
if (password !== password_2)
return next(boom.unauthorized('Passwords do not match.'))
//check if password is valid
if (!Password.validate(password)) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习以前在jQuery中使用普通JavaScript所做的事情。
我有我在互联网上找到的要解决的示例,这确实给了我很多麻烦。
我正在尝试div.single点击删除父对象button.remove。
这是代码;
var btn = document.getElementsByClassName('remove')
for (var i = 0; i < btn.length; i++) {
btn[i].addEventListener('click',function (e) {
e.parentNode.parentNode.removeChild(e.parentNode);
} , false);
}Run Code Online (Sandbox Code Playgroud)
<div class="single">
<img src="http://via.placeholder.com/150x150">
<button type="button" class="remove">X1</button>
</div>
<div class="single">
<img src="http://via.placeholder.com/150x150">
<button type="button" class="remove">X2</button>
</div>
<div class="single">
<img src="http://via.placeholder.com/150x150">
<button type="button" class="remove">X3</button>
</div>
<div class="single">
<img src="http://via.placeholder.com/150x150">
<button type="button" class="remove">X4</button>
</div>Run Code Online (Sandbox Code Playgroud)
我出错了e.parentNode is undefined。
这是执行相同操作的jQuery代码。
$(document).ready(function() {
$(document).on('click', '.remove', function () {
$(this).parent('.single').remove()
})
})
Run Code Online (Sandbox Code Playgroud)
感谢您的任何答案。