问题标签 [jestjs]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
javascript - React + Jest - 在 IMG 标签上测试 `error` 事件
有什么方法可以触发标签error
事件来测试我的回调?例如,给定这个组件,img
onError
这个测试套件:
javascript - 开玩笑 - querySelector('html, body') 返回奇怪的对象
我正在测试一个InfiniteScroll 组件,但是遇到了这个奇怪的问题;querySelector('html, body')
不具有上述方法所期望的属性(例如 , , , clientHeight
,innerHeight
等querySelector
),但具有我怀疑来自.style
addEventListener
_readOnly
_tagName
_created
_ownerDocument
jsdom
我querySelector('html, body')
在测试套件中运行它来滚动浏览器。document.querySelector
这是测试套件中的一个片段:
这是InfiniteScroll 组件的代码:
有什么方法可以访问上述预期的属性吗?谢谢。
javascript - 用 Jest 测试 XHR
我有这个简单的测试用例:
关键是:当我jest
在我的终端上做时,似乎它没有请求http://google.com
. 我认为这是因为 Jest 在后台使用jsdom并且它无法从浏览器本身重现 HTTP 请求。
建议?
注意:出现任何错误,测试通过,但未发出请求。
node.js - 在 Ubuntu 上执行 Jest 时出现内存不足错误
我正在尝试在 Ubuntu 14.04.02 上,在具有 4gb RAM 的虚拟机中执行 Jest。节点版本 0.12.2,npm 2.0.0-alpha-5
免费给我看:
当我运行 npm test 时,我不断收到各种内存不足错误:
知道最低内存要求是什么......或者我是否有错误配置导致这种情况?
javascript - 如何使用 React.createElement() 测试在 Render 中创建的子 React 组件
我正在尝试测试建立在一些临时反应元素代码之上的自定义反应元素:
this._onControlChange 根据文本字段值操作状态。这是我想要测试的,文本字段的不同输入会触发组件的不同状态。
笑话代码:
我尝试为 _onControlChange 模拟函数以查看它是否被调用,它被调用了 0 次。我还尝试在模拟()调用之前和之后查看 customField var 的状态,但没有任何变化。我想知道我是否遗漏了一些东西来模拟在文本字段中输入
我已经尝试了所有按标签、类型和类进行选择的选项,但均未成功。当 console.log 渲染组件时,我可以看到 textfield 元素。有没有办法通过 ref 获取 TextField 的实例?
react-router - react-router的开玩笑测试
我正在尝试为 react-router Route 模块编写一个简单的笑话测试。
该组件有一个按钮,当单击它时,通过使用“transitionTo”方法可以编程导航到另一条路线。
即使在添加了 stubRouterContext 实用程序(如此处所述)并将我的 UserDetails 组件包装在 stubRouterContext 中之后,我仍然不断收到以下错误:
TypeError: Property 'transitionTo' of object #<Object> is not a function
我正在使用 react 12.2、react-router 12.4 和 jest 2.2
我的虚拟组件:
我的测试文件:
我的 stub-router-context.cjsx 文件:
reactjs - 对象原型只能是 Object 或 null
我正在尝试jest
对我的程序运行测试,react
但不断得到:
Object prototype may only be an Object or null
我的测试如下所示:
我的代码看起来像这样:
Stat
被定义为预期但CoPays
抛出错误。我正在使用启用的react-tools
处理器。harmony
这是堆栈跟踪:
continuous-integration - TRAVIS-CI 上的 JEST 测试出错
错误
当我尝试开始 JEST 测试时会发生这种情况,这只是 JEST 教程中的示例测试,看起来像
使用 JEST 进行本地测试运行良好。
尝试在travis-ci上开始mocha测试,没关系!
但是我在 ReactJS 上的项目和我他们建议使用 JEST 进行测试。
如何解决这个问题?
unit-testing - jest js 在一个文件中进行多个测试
我在一个文件中有多个测试,但输出只显示一个测试正在运行。如果我没有通过任何一项测试,它会返回失败,但仍然只显示它正在测试其中一项。
这是我设置的
输出如下
我有点困惑为什么它没有显示 2 个测试。有人有想法么?
jquery - Testing React click event in Jest fails because the Jquery can't be applied - How can I test it?
I have a React class like so
and I also have a Jest test file that is checking whether the class was toggled correcly when the arrow was clicked.
Now I've been console logging what happens in the toggleFooter function and I know that the function works correctly. The classes are toggled but the test still fails.
Any ideas how I can test the behaviour of the button? I imagine that the issue is something to do with how the test actually renders the test DOM. I've tried using jQuery to assert that the classes are toggled correctly but this also doesn't work (I assume because of the reason above).
Any help would be really appreciated.