我有一个ember-cli 0.2.7
using Ember.js 1.12.0
应用程序的一段代码如下所示:
controllers/cart.js
import Ember from 'ember';
export default Ember.Controller.extend({
footwearInCart: Ember.computed('[email protected] /cdn-cgi/l/email-protection', function() {
return this.get('model').any(product => product.get('category').includes('Footwear'));
})
});
它会遍历模型中的所有对象,如果其类别属性中有“鞋类”,则返回 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 returns true if the category property of product in cart contains the word "Footwear"');
});
当我运行应用程序时,代码按照应有的方式工作,但是PhantomJS
显然无法识别 .includes 方法。 (该方法记录在此处String.prototype.includes() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
如何让 PhantomJS 识别 .includes 方法?
Thanks!