samedi 11 juillet 2015

How to test String.prototype.includes in PhantomJS

I have an ember-cli 0.2.7 using Ember.js 1.12.0 app with a piece of code that looks like:

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'));
    })
});

It goes through all the objects in the model and returns true if their category property has 'footwear' in it.

I'm trying to test it like so:

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"');
});

The code works the way it should when I run the app, but PhantomJS apparently does not recognise the .includes method. (The method is documented here String.prototype.includes()

How can I get PhantomJS to recognize the .includes method?

Thanks!




Aucun commentaire:

Enregistrer un commentaire