Tôi có một ember-cli 0.2.7
sử dụng Ember.js 1.12.0
ứng dụng với một đoạn mã mà trông giống như:Làm thế nào để kiểm tra String.prototype.includes trong PhantomJS
controllers/cart.js
import Ember from 'ember';
export default Ember.Controller.extend({
footwearInCart: Ember.computed('[email protected]', function() {
return this.get('model').any(product => product.get('category').includes('Footwear'));
})
});
Nó đi qua tất cả các đối tượng trong mô hình và trả về true nếu thuộc tính thể loại của chúng có 'giày' trong đó.
Tôi đang cố gắng để kiểm tra nó như vậy:
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"');
});
Mã này hoạt động theo cách đó nên khi tôi chạy ứng dụng, nhưng PhantomJS
dường như không nhận ra phương pháp .includes. (Phương pháp này được ghi chép lại đây String.prototype.includes()
Làm thế nào tôi có thể nhận được PhantomJS để nhận ra phương pháp .includes?
Cảm ơn!
'includes' hiện chỉ được triển khai trong Chrome. Mã của bạn không thể hoạt động trong Firefox, Safari và IE cũng như trong PhantomJS –
Được quản lý để làm cho nó hoạt động bằng cách sử dụng một polyfill. Thử nghiệm nó trong FF, Safari, & PhantomJS và nó hoạt động. – zshnr