Title: Unit test computed property on an Ember controller
Tags: unit-testing;ember.js;ember-cli;qunit;ember-qunit
Question: The code from my controllers/cart.js: 

```export default Ember.Controller.extend({
  cartTotal: Ember.computed('model.@each.subTotal', function() {
    return this.model.reduce(function(subTotal, product) {
      var total = subTotal + product.get('subTotal');
      return total;
    }, 0);
  })
)};
```

This computed property loops over all the elements in the model, adding all the values of the ```subTotal``` property, returning a ```cart total```.

cart-test.js

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

moduleFor('controller:cart', {
  // Specify the other units that are required for this test.
  // needs: ['controller:foo']
});

test('it exists', function(assert) {
  var controller = this.subject();
  assert.ok(controller);
});

test('cartTotal function exists', function(assert) {
  var controller = this.subject();
  assert.equal(controller.get('cartTotal'), 30, 'The cart total function exists');
});
```

The test fails with ```TypeError: Cannot read property 'reduce' of null``` because it obviously doesn't have a model to loop over. 

How can I mock the dependencies of the ```cartTotal``` computed property to make the test pass?

Thanks!

Comment: Can you add the rest of your test's code?

Comment: done. edited the post

Here is the accepted answer: Something along these lines maybe?

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

import Ember from 'ember';

var products = [
  Ember.Object.create({ name: 'shoe', 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('cartTotal', function(assert) {
  this.controller.set('model', model);
  assert.equal(this.controller.get('cartTotal'), 30, 'The cart total function exists');
});
```

Comment for this answer: Yeah, I just pulled examples from different sources and don't have an actual ember-cli app to test stuff in so I don't know why importing the model doesn't work. Oh well.
Comment for this answer: yes! With a little difference: instead of `Product.create` we could not even import our model and instead use `Ember.Object.create`

In fact with the `Product.create` I got errors. It worked with Ember.Object.create. 

If you make the changes to your answer I shall mark it as the correct one.

Thanks a lot for your help!
Comment for this answer: it was importing. it failed with an error to use `store.createRecord` instead of `Product.create`.

Here is another answer: One way to deal with this would be to stub the model in the ```beforeEach``` hook:

```var sampleModel = [ // sample data that follows your actual model structure ]

moduleFor('controller:cart', {
  beforeEach() {
    this.controller = this.subject(); // allows you to access it in the tests without having to redefine it each time
    this.controller.set('model', sampleModel);
  }
});
```

Comment for this answer: Oups, used an object instead of an array x.x
Comment for this answer: Thanks. I've edited my first post with the result I got from trying this out. I have a feeling I may not be doing it correctly, but I feel like I got closer.
Comment for this answer: Your answer was going down the right path though :)

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:07/08/15', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<unit-testing><ember.js><ember-cli><qunit><ember-qunit>', 'Title': 'Unit test computed property on an Ember controller', 'ViewCount': 2500, 'id': 31294392, 'user_AboutMe': '', 'user_AccountId': 5948116.0, 'user_DisplayName': 'zshnr', 'user_Reputation': 279.0, 'user_Views': 17.0, 'user_id': 4677044.0}}