在ember-app-kit中使用testem运行测试时,api-stubs失败 [英] api-stubs failing when running tests with testem in ember-app-kit

查看:137
本文介绍了在ember-app-kit中使用testem运行测试时,api-stubs失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ember-app-kit中提供的api存根进行测试。

I am trying to make use of the api-stubs provided in ember-app-kit for testing.

当我查看网站时,存根正常工作浏览器,当我通过在浏览器中维护 / tests 来运行测试。

The stubs work correctly when I view the site in the browser, and when I run the tests by visting /tests in the browser.

但是,当我运行从test命令行测试(通过运行 grunt test:server ),测试失败,因为存根数据未返回。

However, when I run the tests from the command line with testem (by running grunt test:server) the tests fail as the stub data isn't returned.

您可以在此找到一个演示此问题的最小示例: https://github.com/tomclose/minimal_eak_test_stub_problem ,从最新版本的ember-app-kit创建。

You can find a minimal example demonstrating the problem here: https://github.com/tomclose/minimal_eak_test_stub_problem, created from the most recent version of ember-app-kit.

我做错了什么?

推荐答案

因为testem的东西运行在端口(7239是吗?)你a)不能运行apistub服务器在同一个端口(已经绑定)。

Because the testem stuff runs on port (7239 is it?) you a) can't run the apistub server ont he same port (already bound).

因此,您必须运行正常的应用程序(端口8000),让testem运行自己的端口..并通过适配器中的主机参数允许testem找到正确的主机:端口组合来实际获取数据。

Thus, you have to run the normal app (port 8000), let testem run on its own port.. and allow testem via the 'host' param in an adapter go find the right host:port combination to actually get data.

同样, cors()过滤器将使:8000测试服务器愿意将数据从端口7239上的某个东西发送回跨域请求。

As well, the addition of the cors() filter will make the :8000 test server willing to send data back to a "cross domain request" from something on port 7239

使用sinon是一个不同的情况(根本不想使用apistub)。我实际上决定不试图使用apistub进行测试,但肯定上述方法非常棒。

The use of sinon is a different case (don't want to use apistub at all). I actually settled on NOT trying to use apistub for testing, but certainly the above approach works great.

这篇关于在ember-app-kit中使用testem运行测试时,api-stubs失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆