Note that there are some explanatory texts on larger screens.

plurals
  1. POTesting Ember.JS Application fails with ReferenceError: Ember is not defined
    primarykey
    data
    text
    <p>After generating a ember.js project via the great yeoman <code>generator-ember</code> (version 0.7.1) I try to execute tests with the integrated <code>mocha</code>.</p> <pre><code>grunt test </code></pre> <p>or </p> <pre><code>npm test </code></pre> <p>The standard test works fine, but it doe not reference the Ember project. So the own model tests throws</p> <pre><code>ReferenceError: Ember is not defined at Context.&lt;anonymous&gt; (/home/lray/workspace/js/mediator/test/spec/source_model_test.js:9:9) at Hook.Runnable.run (/home/lray/workspace/js/mediator/node_modules/mocha/lib/runnable.js:213:32) at next (/home/lray/workspace/js/mediator/node_modules/mocha/lib/runner.js:243:10) at Object._onImmediate (/home/lray/workspace/js/mediator/node_modules/mocha/lib/runner.js:254:5) at processImmediate [as _immediateCallback] (timers.js:330:15) </code></pre> <p>This is the mentioned test...</p> <pre><code>'use strict'; (function () { describe('Mediator.Source (Model)', function () { beforeEach(function() { Ember.run(function () { Mediator.reset(); }); Ember.testing = true; }); afterEach(function () { Ember.testing = false; }); describe('initialize like expected', function () { it('should return the given parameters correctly', function(){ var oItem; Ember.run(function () { // Won't actually load until the end of the run-block. oItem = Mediator.Source.find(1); }); expect(oItem.get("id")).to.be.equal("myId"); expect(oItem.get("name")).to.be.equal("myName"); expect(oItem.additional).to.be.false(); }) }) }); })(); </code></pre> <p>My <code>package.json</code> looks pretty untouched:</p> <pre><code>{ "name": "mediator", "version": "0.0.1", "dependencies": { }, "devDependencies": { "grunt": "~0.4.1", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-concat": "~0.3.0", "grunt-contrib-coffee": "~0.7.0", "grunt-contrib-uglify": "~0.2.0", "grunt-contrib-compass": "~0.5.0", "grunt-contrib-jshint": "~0.6.3", "grunt-contrib-cssmin": "~0.6.0", "grunt-contrib-connect": "~0.3.0", "grunt-contrib-clean": "~0.5.0", "grunt-contrib-htmlmin": "~0.1.3", "grunt-contrib-imagemin": "0.1.4", "grunt-contrib-watch": "~0.5.2", "grunt-rev": "~0.1.0", "grunt-usemin": "~0.1.12", "grunt-mocha": "~0.4.1", "grunt-open": "~0.2.0", "grunt-svgmin": "~0.2.0", "grunt-concurrent": "~0.3.0", "load-grunt-tasks": "~0.1.0", "connect-livereload": "~0.2.0", "grunt-ember-templates": "0.4.14", "time-grunt": "~0.1.1", "grunt-neuter": "~0.5.0", "mocha": "~1.9.0", "expect.js": "~0.2.0" }, "scripts": { "test": "mocha --recursive test/spec/*.js" }, "engines": { "node": "&gt;=0.8.0" } } </code></pre> <p><strong>Update:</strong> When adding <code>require("ember");</code> to the test case file, <code>npm test</code> complains</p> <pre><code>&gt; mediator@0.0.1 test /home/lray/workspace/js/mediator &gt; mocha --recursive test/spec/*.js module.js:340 throw err; ^ Error: Cannot find module 'ember' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at Object.&lt;anonymous&gt; (/home/lray/workspace/js/mediator/test/spec/source_model_test.js:4:1) </code></pre> <p>while <code>grunt test</code> happily just ignores the test file.</p> <p>Do I have to somehow fit together a connection to Ember differently? How is the best way to do so? Thanks in advance... </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload