Skip to content

Instantly share code, notes, and snippets.

@oliverbarnes
Last active August 29, 2015 14:26
Show Gist options
  • Save oliverbarnes/1385658fb7376bcdd687 to your computer and use it in GitHub Desktop.
Save oliverbarnes/1385658fb7376bcdd687 to your computer and use it in GitHub Desktop.
ember model unit test error
//tests/unit/models/proposal.js
/* jshint expr:true */
import {
describe,
describeModule,
it,
beforeEach,
afterEach
} from 'ember-mocha';
import { expect } from 'chai';
import Resource from '../../../models/proposal';
var supports;
describeModule('model:proposal', 'Unit | Model| Proposal',{}, function() {
beforeEach(function() {
Resource.prototype.container = this.container;
// Use a non-standard name, i.e. pluralized instead of singular
this.container.register('model:proposalz', Resource, {});
});
afterEach(function() {
delete Resource.prototype.container;
});
describe('#toggleSupport', function() {
describe('when proposal is not supported yet', function() {
it('adds a support to it', function() {
expect(this.subject().get('supports')).to.eql([]);
this.subject().toggleSupport;
expect(this.subject().get('supports')).to.eql(supports);
});
});
});
});
//error
not ok 65 PhantomJS 1.9 - Unit | Model| Proposal TestLoader Failures client/tests/unit/models/proposal-test: could not be loaded
---
message: >
'undefined' is not a function (evaluating 'ember_mocha.beforeEach')
stack: >
TypeError: 'undefined' is not a function (evaluating 'ember_mocha.beforeEach')
at http://localhost:7357/assets/client.js:2629
at moduleBody (http://localhost:7357/assets/test-support.js:1833)
at http://localhost:7357/assets/test-support.js:14773
at createModule (http://localhost:7357/assets/test-support.js:1838)
at describeModule (http://localhost:7357/assets/test-support.js:1732)
at http://localhost:7357/assets/client.js:2644
at http://localhost:7357/assets/vendor.js:150
at tryFinally (http://localhost:7357/assets/vendor.js:30)
at http://localhost:7357/assets/vendor.js:156
at http://localhost:7357/assets/test-loader.js:29
at http://localhost:7357/assets/test-loader.js:21
at http://localhost:7357/assets/test-loader.js:40
at http://localhost:7357/assets/test-support.js:14840
@pixelhandler
Copy link

@oliverbarnes see the mocha docs on using before, beforeEach etc. at http://mochajs.org

describe('hooks', function() {

  before(function() {
    // runs before all tests in this block
  });

  after(function() {
    // runs after all tests in this block
  });

  beforeEach(function() {
    // runs before each test in this block
  });

  afterEach(function() {
    // runs after each test in this block
  });

  // test cases
});

@pixelhandler
Copy link

Also do you know if the ember-mocha provides this.container ?

@oliverbarnes
Copy link
Author

I don't, looking into it. about beforeEach, you mean they should be within the describe('#toggleSupport', function() { block rather than the describeModule?

@pixelhandler
Copy link

@oliverbarnes yeah the way I have the beforeEach in the EJR blueprint is specifically for the Ember-QUnit test module setup and teardown. So with Mocha that is done differently, more BDD like syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment