- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有我想测试的各种触摸事件的回调。例如,“touchstart”事件使用触摸的坐标来设置我的类的成员:
NavigationUI.prototype.touchStart = function(evt) {
this.interacting = true;
this.startPoint = this.getTouchXY(evt);
};
NavigationUI.prototype.getTouchXY = function(evt) {
var rect = this.element.getBoundingClientRect();
return {
x: evt.targetTouches[0].clientX - rect.left,
y: evt.targetTouches[0].clientY - rect.top
};
};
我没有使用 jQuery。为了测试这个函数,我需要在已知位置创建一个 div,创建一个 Touch 事件来正确设置第一个 targetTouches Touch 的 clientX 和 clientY 变量,然后触发该事件并检查回调是否执行了它应该执行的操作。我对鼠标事件有类似的回调。示例测试是:
test('test mouseDownCallback', function() {
var div, evt, navElement;
div = document.createElement('div');
div.setAttribute('style', 'position: fixed; left: 0px; top: 0px;');
document.body.appendChild(div);
navElement = new lasertutor.NavigationUI(div);
evt = document.createEvent("MouseEvent");
evt.initMouseEvent("mousedown", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
div.dispatchEvent(evt);
ok(navElement.interacting, "mousedown doesn't set interacting");
return deepEqual({
x: 0,
y: 0
}, navElement.startPoint);
});
但是,似乎没有文档可以尝试对触摸事件执行此操作。好像有a description of the Touch Event Interface无法触发,an Apple Developer page on the initTouchEvent function没有提及任何构建所需 Touch 或 TouchList 参数的方法,并且 another SO question从 2011 年开始,不包括使用任何位置数据填充触摸事件。
我当前的测试如下所示,并使用 Apple Dev 页面中的 initTouchEvent 规范,并尝试简单地模拟 TouchList 和 Touch 对象:
test("test TouchStartCallback", function() {
var div, evt, navElement, touch1;
div = document.createElement('div');
div.setAttribute('style', 'position: fixed; left: 0px; top: 0px;');
document.body.appendChild(div);
navElement = new lasertutor.NavigationUI(div);
evt = document.createEvent("TouchEvent");
touch1 = document.createTouch({
clientX: 0,
clientY: 0,
id: 0,
pageX: 0,
pageY: 0,
screenX: 0,
screenY: 0,
target: div
});
evt.initTouchEvent("touchstart", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, [touch1], [touch1], [touch1], 1, 0);
div.dispatchEvent(evt);
ok(navElement.interacting, "touchstart doesn't set interacting");
return deepEqual({
x: 0,
y: 0
}, navElement.startPoint);
});
我将此测试作为 grunt Qunit 任务的一部分运行。它失败了,没有错误,表明 ok 和 deepEqual 断言都不正确。此测试的 mouseEvent 版本通过了。
最佳答案
您是否正确使用 document.createTouch ?根据Safari developer您需要传递事件发生的 View (窗口)。
createTouch( DOMWindow View 、EventTarget 目标、长标识符、长 pageX、长 pageY、长 screenX、长 screenY)
touch1 = document.createTouch(window, div, 1, 0, 0, 0, 0);
关于javascript - 如何使用纯 JavaScript 在 grunt-run qunit 测试中触发 TouchEvent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23597493/
我正在尝试将 QUnit 与 Meteor 应用程序一起使用。这应该可能吗?有什么推荐的款式吗? 我试图通过为“/test”创建路由来制作一个“自我测试”的应用程序,但似乎 QUnit 没有运行我的测
我记得曾经在 QUnit 的测试运行器工具栏中看到过 QUnit 测试模块选择列表的屏幕截图。我的印象是,在选择列表中选择一个模块会导致该模块的测试运行。 问题:QUnit 是否真的存在这样的功能 O
是否有任何示例说明如何将 Qunit 实现到完整的开发周期中。现有示例似乎需要将测试脚本硬编码到生产源代码中。目前有没有办法将单元测试和源代码分开?我只想要开发代码中的单元测试代码,而不是生产代码。
此页面上的信息似乎不太可能出现——https://github.com/kof/node-qunit .我有一个安装 nodejs 并安装了 node-quit 模块的设置。我有测试运行器并执行命令
我刚找到 qHint ,一种将 jsHint 测试集成到 Qunit 中的方法......但它在本地(我不是指本地主机)中不起作用,除了在 Firefox 中。 所以我想添加一个“警告”或“通知”,而
我正在研究用于 JavaScript 单元测试的 QUnit。我处于一种奇怪的情况,我正在检查从 Ajax 调用返回的值。 对于下面的测试,我是故意让它不及格的。 // test to check i
js文件 window.onload = function() { document.getElementById('example').addEventListener('mousedown
我当前的单元测试使用 QUnit并且它们按照 QUnit website 上的描述执行.基本上我所有的测试都编译成 tests.js这包含在 index.html 中: QUnit E
我已经想出如何使用 karma 测试运行器测试我的代码,但我不知道如何在网页上测试 UI 功能。 我有一个简单的计算器程序 (calculator.js): window.onload = funct
我刚刚开始使用 QUnit 进行 ui 测试,所以我确定我缺少 qunit-fixture 的一些基本用例。我认为它对测试 DOM 操作很有用,但后来我意识到我的 DOM 操作函数都不知道任何关于 q
我正在通过 Qunit 框架进行 javaScript 单元测试。我有 DOM 对象,其中包含表单和文本框。 我会将上面的 DOM 对象添加到 qunit-f
我有两个 XXXTest.html 文件,每个都与此类似: Somet
我想为 QUnit 编写自定义 assert 函数来检查 actual 字符串是否与 expected 正则表达式匹配。在this question的帮助下我编写了第一个按预期工作的基本版本: QUn
我正在使用QUnit在麻省理工学院许可的项目部分用 TypeScript 编写。我有一些 TS 函数接受 QUnit 作为参数并希望将它们键入作为其接口(interface)来自the typing
最初由 Andreas Haller 在邮件列表上发布,在此处重新发布,以便“qunit-bdd”标签可供其他人使用。 ember-qunit adds a handy moduleFor helpe
使用 instructions here ,我正在尝试通过 chutzpah 配置 QUnit 测试 错误是: Error: Error: Error: Called start() outside
我在为使用 Twitter Bootstrap 的项目编写 qUnit 测试时遇到了困难。当生成模态时,它将覆盖层放在 qunit-fixture 之外,因此当运行下一个测试时,覆盖层不会被删除。有人
这是我的测试代码。 test("user login", function(){ visit("/sessions/new").then(function() { fillIn('inpu
我有一个问题,当我尝试在 div id="qunit-fixture"中附加或设置 HTML 代码时,使用在 ReSharper 8 下运行的 Qunit 进行测试。div id="qunit-fix
抱歉,如果这很明显,但是如果我们想断言某个方法返回 false,QUnit 中是否有 notOK 或等效函数? 我看不到在 documentation 中否定 OK 的方法. 我试过: !ok...
我是一名优秀的程序员,十分优秀!