问题标签 [ember-qunit]

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.

0 投票
2 回答
2396 浏览

ember.js - 在 Ember.js 中测试抛出错误

使用集成的 QUnit 测试框架,我需要测试是否访问路由会导致抛出错误。

路由中有一个 Handlebars 助手,它应该在某些条件下抛出错误(断言失败)。如何测试是否抛出此错误?

这是我到目前为止得到的:

但它不起作用,因为错误没有被捕获throws(...)并冒泡到测试框架,将此测试标记为失败。

这是测试输出:

作为visit('/missing')返回一个承诺,人们会假设 using.then(success, error)会起作用,但事实并非如此。

0 投票
1 回答
252 浏览

unit-testing - Ember-qunit 单元测试助手:它们现在如何工作?

直到最近我才包括文件......

https://raw.githubusercontent.com/rwjblue/ember-qunit-builds/master/dist/globals/main.js

...在一个“TestRunner”页面中,我将打开该页面来运行我所有的 Ember 单元测试。一切都很棒。

几天前,那个文件从 github 上消失了,所以我开始寻找让我的单元测试(例如 moduleForComponent 测试)运行的新方法。

我首先尝试简单地包含来自ember-qunit-builds存储库的ember-qunit.js文件,但是像找不到模块“ember”这样的错误又回来了。

我是否正确地说 ember-qunit 在某种程度上取决于ember-test-helpers?在我的测试代码之前我应该​​包括哪些引用我有点迷茫......我觉得我错过了一些与 ES6 样式模块(导出/导入等)相关的东西,我对此几乎没有经验。

有人可以在这里指出我正确的方向吗?我应该在我的“TestRunner.html”页面上包含什么来让“moduleForComponent”风格的测试再次发生?

注意:我在一个 .NET 环境中,我知道经常提到的“安装”这些东西的工具(如 Bower/npm)并不真正可用(这些是让它工作的必要条件吗?)。

0 投票
1 回答
383 浏览

ember.js - 测试期间组件未正确呈现

我正在为我的 Ember CLI 应用程序编写集成测试,我的一个测试每次都失败。这是我目前的测试:

当它导航到 时/collaborate/projects/:id,我收到错误“无法读取 null 的属性 'setLegend'。” 我将其追溯到我的组件:

请注意,如果我更改updateChart为,测试确实通过了:

为什么它不会在测试期间设置该变量?它在开发和生产中运行良好,所以我不确定为什么会这样。我假设这是因为didInsertElement在测试运行时没有触发。想法?想法?

灰烬版本:

编辑

难道Foo()是来自外部模块?也许测试无权访问它,因此无法将其添加到页面中?我对此表示怀疑,并且我已经尝试将其添加到.jshintrc,但我想它仍然可能与此有关。我还在Foo运行测试时进行了控制台记录,它确实显示在控制台中。

老实说,这可能与将其插入 DOM 有关。我在初始化其他组件时遇到了问题,所以它可能didInsertElement没有按照我的想法运行。

0 投票
0 回答
826 浏览

ember.js - 触发事件需要 Ember 集成测试中的特定选项?

no_results为我的 Chosen 组件(使用Chosen jQuery 插件)添加了自定义文本,并且我正在尝试编写集成测试以查看它是否正常工作。为此,我需要找到一些方法来触发chosen:no_results事件。

基本上,我的测试分为以下几个部分:

  1. 用户单击所选组件。它们会显示一个下拉菜单,顶部有一个搜索栏。
  2. 用户使用下拉菜单中不存在的选项填写搜索栏(例如,他们输入“Foo”,但下拉菜单仅包含“Bar”)。而不是默认的选择对话框,而是显示“未找到结果。添加新选项:”,并带有显示新选项的链接(例如,“未找到结果。添加新选项:'Foo', " 以 "Foo" 作为链接)。
  3. 他们单击新选项,然后将其添加到下拉列表中。

我目前卡在2。

我已经尝试过简单地填写输入字段,如下所示:

然而,那失败了。测试返回的不是预期的结果""。我在 last 之前放了一个断点equal#ember-testing窗口仍然显示默认的下拉选项而不是no_results文本。

所以,然后我意识到这fillIn实际上并不是在输入文本,并且我得出结论认为该事件是由于按键而触发的。考虑到这一点,我尝试像这样重写测试:

我也尝试触发keyupandkeydown事件。结果与第一次测试相同。

我还尝试了对组件的单元测试,但似乎我无法触发事件,并且组件正在侦听chosen:no_results事件。

最后,我尝试在测试中直接触发chosen:no_results事件:

显然,该事件确实触发了,但我得到了一个错误。似乎chosen:no_results事件在事件选项中传递了 Chosen 对象,这是我的组件运行所必需的。我无法从测试本身访问它,所以我要么需要找到某种方法来使用测试助手来触发它,要么我必须找到某种方法从测试本身传入 Chosen 对象。

我将如何进行测试?

0 投票
1 回答
2050 浏览

ember.js - How can I get source maps to work when running tests using ember-qunit for an ember app built on ember-cli

I have an Ember app built using ember-cli and I'm writing my tests using the ember-qunit testing adapter and running them in the browser using testem as instructed in the ember-cli documentation. Although debugging in Google Chrome works fine when I'm interesting with my app, I am unable to use many debugging features such as breakpoints when running my tests.

I often run into a problem that my tests fail despite my actual app seeming to work properly, and to investigate the problem I would like to step through code while my tests are running.

But when I step into code that appears in vendor.js I just just see the following contents in my vendor.js:

These two lines are lines 6 & 7 of the file. The lines before this are blank, and these two lines are the last lines in the file. The debugger has the first line of the file highlighted as if that's the current location in the source, but it cannot show the source for some reason.

I can proceed to step through the code, but I can't see anything.

However, if I find vendor.js in the list of sources in the developer tools sources file list then it opens as a separate source tab and I can see all my code. At this point I have two tabs labeled vendor.js, one with all my vendor assets and one with just those line quoted above.

I am guessing that there is something different between how my tests are served and how my app is served in the development environment that is confusing Chrome.

I am using the following versions of things:

Although I've poked around a bunch I don't really have any leads on where the problem is stemming from. Perhaps it's related to how testem is running the tests? Or could it be something that gets included in my tests has a messed up source map?

I appreciate any help or ideas.

0 投票
1 回答
2075 浏览

ember.js - PhantomJS 2.0 挂在 ember 测试中

我有一个简单的 ember-cli 应用程序。我用 运行单元测试ember test,它在 phantomJS 中运行它们。使用测试Function.prototype.bind失败,因为 phantom 1.9.x 缺少该 API 的众所周知的问题。我安装了 phantom 2.0,但现在当我运行时ember test,成功构建后,测试从未运行,它只是挂在那里,没有错误,什么都没有。

关于问题可能在这里,或者如何追踪它的任何想法?

操作系统是 Windows。

0 投票
0 回答
160 浏览

ember.js - Pretender and QUnit: Error: Assertion Failed: The response from a findQuery must be an Array, not undefined

A recent update seems to have broken my tests. I'm using Pretender to mock server calls, and I'm getting the error Error: Assertion Failed: The response from a findQuery must be an Array, not undefined.

Note that I don't get errors when I visit that page in my app. This error only appears when I run the test.

I've already looked at this, this, and this, but none of those solutions seem to apply in my case.

Here's the relevant code in my Pretender helper:

And this is the test:

Note that this only affects tests using dynamic routes like the one above. Tests that use this route work normally:

I tried bypassing the find by doing this:

However, I still get the same error.

Any ideas? How would I debug this issue?

Assorted versions:

0 投票
1 回答
395 浏览

ember.js - 使验收测试顺序依赖?

有什么办法可以让测试顺序依赖,所以测试 2 在测试 1 完成之前不会开始?去 localhost:4200/tests 以不确定的方式运行它们,有时它会以正确的顺序运行并且工作正常,但有时它会乱序运行它们,这可能会导致问题,有没有办法强制特定的顺序但保留它们在单独的测试功能中,我总是可以将该测试的所有内容放在一个大测试功能中,以便顺序始终有效,但我觉得它们应该被分解成自己的功能,任何指导将不胜感激?下面的示例只是我希望订单看起来像的示例测试

0 投票
1 回答
325 浏览

javascript - ember-cli extend assert with custom assertion helpers

In the latest ember-cli, in the unit tests the test function expect as last parameter a function which would have the assert object as first parameter.

I was wondering how can I extend this object to add my own custom assertion helpers?

For example I want to add a controlDisabled helper that would return true if the control is disabled, and false otherwise. So somewhere (but not in each test files) I want to extend that assert object given as paramter like so:

#xA;

Where should I define this?

0 投票
1 回答
864 浏览

ember.js - 我在哪里使用 Pretender 来启用带有 rails-csrf 的 Ember Qunit 集成测试?

我们在我们的 ember-cli 应用程序中使用rails-csrf 。rails-csrf 上的 README

请务必模拟对 csrf 服务器端点的调用。否则你的测试将失败

"error while processing route: [route]"

浏览器控制台中的消息。例如:

我理解这里的问题(我们的集成测试确实显示了这个错误)并且我理解Pretender是如何解决它的。我已经通过ember-cli-pretender安装了 Pretender 。

我不明白的是如何确保这个代码片段 - Pretender 模拟的配置 - 正在工作。我将它安装在setup集成测试模块的块中,它被调用,但错误仍然存​​在并且测试仍然没有通过。

这是当前的非工作状态:

模拟被调用,但无论它返回什么显然都不足以用于 rails-csrf。看起来beforeModel应用程序路由中的调用正在返回一个承诺;目前尚不清楚这是否符合预期并得到解决。

(这个问题表面上与这个老问题相似,但是在 Ember 中处理这个问题的可用工具已经发生了显着变化。)