标签: ember-cli

Ember-cli单元测试关系的需求

我正在进行单元测试,感觉我做错了.我有一个'主'对象有很多关系

author: belongsTo('person', { async: true }),
title: attr('string'),
category: belongsTo('category', { async: true }),
impact: belongsTo('impact', { async: true }),
status: attr('string'),
createdDate: attr('moment'),
submittedDate: attr('moment'),
authorOrg: belongsTo('organization', { async: true }),
locations: hasMany('location', { async: true }),
audits: hasMany('audit', { async: true })
Run Code Online (Sandbox Code Playgroud)

每次我在单元测试及其相关项目的工作时间(person,category,impact),我有重现所有的needs,我的"主"对象有值.category当我只关心字符串的名称及其与'main'对象之间的关系时,我觉得我的位置单元测试不合适

// location/model-test.js
import {
  moduleForModel,
  test
} from 'ember-qunit';

moduleForModel('location', 'Location', {
  // Specify the other units that are required for this test.
  needs: …
Run Code Online (Sandbox Code Playgroud)

unit-testing ember.js ember-testing ember-cli

11
推荐指数
1
解决办法
369
查看次数

如何使用qunit在Ember单元测试中依赖商店作为服务?

根据博客文章ember-data版本1.0.0-beta.16,商店现在可以用作服务:

TweetComposerComponent = Ember.Component.extend({
  store: Ember.inject.service()      
});
Run Code Online (Sandbox Code Playgroud)

但是,我无法弄清楚如何qunit对这样的组件进行单元测试.我尝试过以下方法:

moduleForComponent('tweet-composer', {
  needs: ['service:store']
});
Run Code Online (Sandbox Code Playgroud)

和:

moduleForComponent('tweet-composer', {
  needs: ['store:main']
});
Run Code Online (Sandbox Code Playgroud)

当我做前者时,我得到一个错误Attempting to register an unknown factory: 'service:store',如果我做后者那么store就是undefined.

思考?

(我正在写一个ember-cli样式应用程序).

更新:

在ember-test-helpers repo中似乎存在一个未解决的问题.

在我等待这个修复的同时,我制作了一个可以作为一种间隙测量的辅助工具(coffeescript):

`import TestModuleForComponent from 'ember-test-helpers/test-module-for-component'`
`import { createModule } from 'ember-qunit/qunit-module'`

# This assumes the last argument, the callbacks, is present, although it
# does support the description being an optional …
Run Code Online (Sandbox Code Playgroud)

ember.js ember-data ember-cli ember-qunit

11
推荐指数
1
解决办法
4186
查看次数

如何在不使用阵列控制器的情况下在Ember模型中实现排序?

每个google结果都与ArrayController排序有关.需要一个排序机制而不使用ArrayController.

有一个模型,其中有排序参数.就像说'sortOrder'作为模型中的一个属性(它将来自后端).

将使用#each渲染此模型,但这应该基于sortOrder属性而不是模型的ID属性进行迭代.

ember.js ember-data ember-cli

11
推荐指数
2
解决办法
9558
查看次数

包含与ember-cli的依赖关系

我正在尝试使用ember-cli来获得一个ember项目,但是我之前依靠rails和资源管道来编译我以前的项目所有的js和(s)css.

我承认对js构建工具的理解很少,如果问题是基本的,那么道歉:我怎样才能看到构建中正在编译/包含哪些依赖项?具体来说,我想在我的项目中包括zurb-foundation和ember-leaflet.我不确定它们是否在那里(至少传单没有出现在项目中 - 使用了一个适用于rails和rail-eak的基本示例).

文件(ember-leaflet等)位于项目的供应商目录中,并通过bower install放置在那里(我假设?); 我是否必须手动将它们包含在root bower.json文件中(目前它们不是); bower.json中的顺序重要吗?

提前致谢.

DJ

ember.js ember-cli

10
推荐指数
1
解决办法
2207
查看次数

ember-cli --proxy适用于GET,但在PUT和POST时失败

我正在尝试将我的应用程序从Ember Appkit移动到ember-cli,我无法复制以前由APIMethod和proxyURL方法提供的代理功能.

我正在启动服务器代理到localhost:3000

ember serve --proxy http://localhost:3000/

这将正确地从rails服务器读取我的数据.但是,当我尝试写入服务器时,我收到一条错误消息

POST http://localhost:4200/api/v1/posts 408 (Request Time-out)

它正试图发布到端口4200,这是服务于它的ember应用程序,但我希望它发布到端口3000.我怎么能这样做呢?

我正在使用ember-cli 0.28,ember 1.5.1,ember-data 1.0.0-beta.7和rails 4.1.

proxy ember.js ember-cli

10
推荐指数
1
解决办法
5944
查看次数

在ember/ember-cli中的子文件夹中生成组件

根据Ember 2.0的准备建议 ......

•通常,用组件替换视图+控制器
•仅在路由级别使用控制器...

......我们应该避开ControllerView支持Components.我无法弄清楚和/或理解如何生成不是components文件夹的直接父代的组件,即components/component-name.js.

我当前的控制器文件夹看起来像:

/controllers
    /account
        index.js
        edit.js
    /business
        index.js
Run Code Online (Sandbox Code Playgroud)

基本上,有一些子文件夹可以根据应用程序的各个部分对逻辑进行分组.我怎样做到这一点只是组件?

看到组件中必须有" - ",我试过,但是出错...

ember generate component account/index-module.js
You specified "account/index-module.js", but due to a bug in Handlebars (< 2.0) slashes within components/helpers are not allowed.
Run Code Online (Sandbox Code Playgroud)

是否所有组件都必须如此

components
    account-index.js
    account-new.js
    business-index.js
Run Code Online (Sandbox Code Playgroud)

即所有在同一个文件夹?这将开始失控,增加了我实际认为是组件(像video-viewer.js,text-editor.js,radio-button.js这样的东西).

我真的想在子文件夹中包含组件,但不确定如何执行此操作.

components
    /media
        /audio
            audio-player.js
        /video
            video-player.js
    /text-editing
        text-editor.js
        editor-toolbar.js
Run Code Online (Sandbox Code Playgroud)

我的组件文件夹已经很糟糕,我刚刚开始:

在此输入图像描述

是否可以将帐户/业务逻辑保留在控制器中(看到它确实说您应该只在路由级别使用控制器)?

我真的很困惑这个"所有组件,所有时间"的惯例.

javascript ember.js ember-cli

10
推荐指数
2
解决办法
3202
查看次数

将LoDash与EmberCLI一起使用

有没有人有一个使用Ember-CLI使用LoDash构建的(简单)ember-app项目的工作示例?(例如:我想在我的路由和控制器中使用lodash,_.someLodashFunc).

我没有在网上看到任何关于如何做到这一点的明确,逐步解释的线索/文章.

如果可能的话,使用lodash v3.0.0(我使用的是最新的ember-cli,v0.1.9).

谢谢,拉卡


我发现了如何,你需要生成一个自定义的lodash("lodash modern").使用lodash-cli:https://lodash.com/custom-builds

在命令控制台上输入:lodash modern ...,然后你会得到一个生成的javascript文件:lodash.custom.js

将该文件放在ember-cli项目的"vendor"目录下.

修改Brocfile,添加:

app.import('vendor/lodash.custom.js', {
  'lodash': [
    'default'
  ]
});
Run Code Online (Sandbox Code Playgroud)

就是这样......你不必在你的任何js文件中执行"import _ from'loodash'".事实上,不要这样做(你会得到一个错误)._ var很容易获得.

例如,我有一个这样的Route对象:

import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    console.log('hohoho: ' + _.chunk(['a', 'b', 'c', 'd'], 2));
    return Ember.Object.create({name: 'Raka'});
  }
});
Run Code Online (Sandbox Code Playgroud)

我可以看到hohoho:,b,c,当我访问那条路线时,我在javascript控制台中打印出来.

更正

你真的不需要那个lodash-cli.

我试过这种方式(我想更合适):

  1. 凉亭安装lodash --save
  2. 在Brocfile.js中,有这一行:app.import('bower_components/lodash/lodash.js');

而已._在路由器/控制器中自动可用.

我对d3做了同样的事情:

  1. 凉亭安装d3 - 保存
  2. 在Brocfile.js中,有这一行:app.import('bower_components/d3/d3.js');

名为'd3'的变量可自动使用.


新增相关链接:

  1. 在ember-cli中导入自定义库
  2. http://tiku.io/questions/2866484/how-to-include-a-local-javascript-im-ember-cli-application(引用:如果你不需要在vendor.js文件中缩小它们,你可以将它们放在public/js中,然后将其作为普通脚本文件包含在app/index.html中.我将此方法用于某些库,如moment.js.公共文件夹在构建期间直接复制到您的站点根目录. )
  3. 在Ember CLI中访问D3等第三方库的正确方法?

ember.js lodash ember-cli

10
推荐指数
2
解决办法
3973
查看次数

子目录中的Ember组件

我已经读过现在支持在/ components中包含目录/文件夹.使用ember-cli我可以生成所需的必要子目录/组件.但是,我似乎无法引用该组件.

例如,如果我是这样的文件夹结构:

app/components/sub/test-comp.js
app/templates/components/sub/test-comp.hbs
Run Code Online (Sandbox Code Playgroud)

引用方式:(在另一个.hbs文件中)

{{test-comp model=model}}
Run Code Online (Sandbox Code Playgroud)

给我以下错误:

A helper named 'test-comp' could not be found
Run Code Online (Sandbox Code Playgroud)

余烬:1.10.0
ember-cli:0.2.0

ember.js ember-cli

10
推荐指数
1
解决办法
5215
查看次数

在Ember CLI Project中使用Broccoli JS移动整个文件夹

我正在开发一个ember-cli项目,我正在开发一个系统,允许我解析尚未加载的模板,并且可能存在于项目结构之外.

我想在我的dist/assets目录中调用一个文件夹templates,在该文件夹中将是所有预编译的模板app/templates/external.这是我目前Brocfile.js用西兰花炖的尝试

var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var stew = require("broccoli-stew");

var app = new EmberApp({
  vendorFiles: {
    "jquery.js": null
  },
  sassOptions: {
      includePaths: [
        'bower_components/bourbon/app/assets/stylesheets/',
        'bower_components/neat/app/assets/stylesheets/',
        'bower_components/bitters/app/assets/stylesheets/'
      ]
    }
});

var additionalTrees = [];

var templateFiles = stew.find(appTree, "assets/app/templates/external");
templateFiles = stew.mv(templateFiles, "assets/app/templates/external", "assets/templates");
additionalTrees.push(templateFiles);

module.exports = app.toTree(additionalTrees);
Run Code Online (Sandbox Code Playgroud)

ember.js ember-cli broccolijs ember-cli-addons

10
推荐指数
1
解决办法
582
查看次数

如何在PhantomJS中测试String.prototype.includes

我有一个ember-cli 0.2.7使用Ember.js 1.12.0应用程序与一段代码看起来像:

controllers/cart.js

import Ember from 'ember';

export default Ember.Controller.extend({

    footwearInCart: Ember.computed('model.@each.category', function() {
        return this.get('model').any(product => product.get('category').includes('Footwear'));
    })
});
Run Code Online (Sandbox Code Playgroud)

它遍历模型中的所有对象,如果其类别属性中包含"鞋类",则返回true.

我试图像这样测试它:

tests/unit/controllers/cart-test.js

import { moduleFor, test } from 'ember-qunit';
import Ember from 'ember';

var products = [Ember.Object.create({name: 'shoe', category: 'Footwear', subTotal: 10}), Ember.Object.create({name: 'shirt', subTotal: 20})];

var model = Ember.ArrayProxy.create({
  content: Ember.A(products)
});

moduleFor('controller:cart', {
  beforeEach() {
    this.controller = this.subject();
  }
});

test('footwearInCart property works', function(assert) {
  this.controller.set('model', model);

  assert.equal(this.controller.get('footwearInCart'), true, 'The footwearInCart function …
Run Code Online (Sandbox Code Playgroud)

javascript phantomjs ember.js ecmascript-6 ember-cli

10
推荐指数
2
解决办法
4160
查看次数