我正在尝试编写一个简单的Ember集成测试,并继续获得令人沮丧的运行循环错误,尽管使用Ember.run.我有一个噩梦,试图让这个工作,如果有人可以帮助我,我会非常感激.具体来说,我可以看到测试登录并开始加载下一页(应该如此),但是一旦测试完成,我就会收到该错误.这是关于第二次测试,第一次测试(因为我认为没有任何异步).
import Ember from 'ember';
import startApp from 'jobs-tuftsdaily/tests/helpers/start-app';
import exists from 'jobs-tuftsdaily/tests/helpers/start-app';
var App;
module('Integration - Landing Page', {
setup: function() {
App = startApp();
},
teardown: function() {
Ember.run(App, 'destroy');
}
});
test('Should load content', function() {
visit('/').then(function() {
ok(exists("*"), "Found HTML!");
ok(exists('label:eq(4)'), "Slug label on page");
});
});
test('Should sign in test user', function() {
Ember.run(function() {
visit('/').andThen(function() {
return fillIn("input[name=email]", "test@test.com");
}).andThen(function() {
return fillIn("input[type=password]", "password");
}).andThen(function() {
return click("button");
}).andThen(function() {
ok(1, "stupid …Run Code Online (Sandbox Code Playgroud) integration-testing ember.js ember-testing ember-cli ember-qunit
我正在尝试使用Ember Testing集成自动化测试.
应用程序在浏览器上运行正常,没有任何错误.我试过简单地跑步
ember test
Run Code Online (Sandbox Code Playgroud)
在命令行上,但得到一堆全局错误,所有测试都失败了.
这些是我得到的错误:
not ok 1 PhantomJS 2.1 - Global error: SyntaxError: Unexpected token ',' at http://localhost:4302/assets/vendor.js, line 145617
not ok 2 PhantomJS 2.1 - Global error: Error: Could not find module ember-metal/core required by: ember-testing/index at http://localhost:4302/assets/test-support.js, line 62
not ok 3 PhantomJS 2.1 - Global error: ReferenceError: Can't find variable: define at http://localhost:4302/assets/tests.js, line 1
...
Run Code Online (Sandbox Code Playgroud)
当我在浏览器上运行测试时,我没有得到语法错误(上面的第一个),第一个错误是
Uncaught Error: Could not find module `analogue/resolver` imported from `analogue/tests/helpers/resolver`
Run Code Online (Sandbox Code Playgroud)
这些对我来说没有意义,因为我不应该编辑vendor.js和它说它找不到的模块.有任何想法吗?
我对Ember很新,以前从未写过测试用例.我目前有一个被用作基类的路由,并将被其他路由扩展,以使用相同的行为进行重定向.这是路线的样子:
import Ember from 'ember';
export default Ember.Route.extend({
redirect: function(){
var user = this.modelFor('application').user;
if(Ember.isEmpty(user.get('auth'))){
this.transitionTo('login');
}
},
model: function(){
return this.modelFor('application').user;
}
});
Run Code Online (Sandbox Code Playgroud)
所以手动测试这个很好,如果我输入屏幕的直接网址,它将重定向到登录.这是我们想要的功能代码.我的任务是编写单元测试,并且无法找到我认为有用的任何东西.这可能是我对理解事物的经验不足,但我需要弄清楚如何测试这段代码.我会喜欢一些帮助,一些解释以及正在做的事情.我必须为这个ember项目进行单元测试和许多其他事情并且非常新我已经浪费了2天时间来研究如何测试这个类.
如何在Ember中测试此代码?一般来说,请向我解释一下这个概念。
// app/routes/products/new.js
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.createRecord('product');
},
actions: {
willTransition() {
this._super(...arguments);
this.get('controller.model').rollbackAttributes();
}
}
});
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么做。可能是存根模型吗?我发现商店在路线测试中不可用。
在Ruby和RSpec之后,所有这些新的JavaScript世界都使您感到困惑。)但是我还是想学习它。
我目前正在他们的网站上浏览官方的EmberJS教程,我就是这个部分.当我运行时,一切都在应用程序本身完美运行,ember serve但问题是我运行新服务的单元测试.我正在运行ember test --server,我收到一个错误,我截取了以下截图:
单元测试代码:
import { moduleFor, test } from 'ember-qunit';
import Ember from 'ember';
const DUMMY_ELEMENT = {};
let MapUtilStub = Ember.Object.extend({
createMap(element, location) {
this.assert.ok(element, 'createMap called with element');
this.assert.ok(location, 'createMap called with location');
return DUMMY_ELEMENT;
}
});
moduleFor('service:maps', 'Unit | Service | maps', {
needs: ['util:google-maps']
});
test('should create a new map if one isnt cached for location', function (assert) {
assert.expect(4);
let stubMapUtil = MapUtilStub.create({ assert });
let mapService …Run Code Online (Sandbox Code Playgroud) 我在Ember应用程序中运行测试时遇到此错误.显然,语法错误(Unexpected token ',')的发生方式使得测试环境的负载失败,因此它会使每一次测试都失败.
$ ember test
version: 1.13.13
Built project successfully. Stored in "/Users/ernesto/code/projects/my-app/frontend/tmp/class-tests_dist-cqvfx9XF.tmp".
not ok 1 PhantomJS 2.0 - global failure
---
actual: >
null
message: >
SyntaxError: Unexpected token ','
Log: |
...
not ok 2 PhantomJS 2.0 - global failure
---
actual: >
null
message: >
Error: Could not find module `frontend/config/environment` imported from `frontend/tests/helpers/resolver`
Log: |
...
not ok 3 PhantomJS 2.0 - global failure
---
actual: >
null
message: >
Error: Assertion Failed: …Run Code Online (Sandbox Code Playgroud) 我写了一些 ember 验收测试用例。问题是当我http://localhost:4200/tests通过 Acceptance访问 URL和过滤器模块时,测试用例运行速度快如闪电。即使这些是在async await函数中编写的。
我想使用 ember 运行循环run.later或run.next. 但这不是解决方案。
有没有办法slow mode在应用程序顶部的某个地方添加(或)是否有任何已经存在的测试助手?所以我可以看到运行中的测试用例。
ember.js ×7
ember-cli ×3
javascript ×3
ember-qunit ×2
ember-data ×1
phantomjs ×1
qunit ×1
syntax-error ×1
unit-testing ×1