css - 用于定位的 jest 测试 css
问题描述
有谁知道如何为此编写一个笑话测试?
loginBtn.onclick = (()=>{
loginForm.style.marginLeft = "0%";
loginText.style.marginLeft = "0%";
});
我已经尝试过了,但它没有用
beforeEach(() => {
document.documentElement.innerHTML = html.toString();
});
test('clicking signup moves the styles', () => {
const loginForm = document.querySelector("form.login");
const loginText = document.querySelector(".title-text .login");
expect(loginForm.style.marginLeft).toBeFalsy();
expect(loginText.style.marginLeft).toBeFalsy();
解决方案
.toBeFalsy() 不会是真的,因为 '0%' 是一个不同于 0 的字符串,它是假的
你将不得不使用toEqual('0%')
这种情况
expect(loginForm.style.marginLeft).toEqual('0%');
expect(loginText.style.marginLeft).toEqual('0%');
推荐阅读
- mongodb - MongoDB查询以获取每个id的最后一条记录
- javascript - 如何从单个选择中获取包含对象的选定选项 - 角度
- visual-studio-code - 在 VSCode Jupyter Notebook 中移动/调整变量资源管理器
- casting - 用于处理播放器控件的 Roku 转换示例代码
- css - 光标不显示 (CSS)
- node.js - 如何解决:部署的 nodejs 应用在 Heroku 上显示为空白
- google-apps-script - Google 表单文件上传:获取文件名
- mysql-workbench - 内置错误:在 mysql 工作台中尝试自动完成时的列表成员
- c - C 中的命名管道丢失信息
- c++ - 我编写了一个简单的矢量程序,在其中我得到了以下输出。你能帮我理解它的输出吗?