diff --git a/blueprints/model-test/index.js b/blueprints/model-test/index.js index 5dc0767032a..d4406a1c08f 100644 --- a/blueprints/model-test/index.js +++ b/blueprints/model-test/index.js @@ -10,7 +10,7 @@ module.exports = useTestFrameworkDetector({ locals: function(options) { var result = ModelBlueprint.locals.apply(this, arguments); - result.friendlyDescription = testInfo.description(options.entity.name, "Unit", "Model"); + result.friendlyTestDescription = testInfo.description(options.entity.name, "Unit", "Model"); return result; } diff --git a/blueprints/model-test/mocha-files/tests/unit/__path__/__test__.js b/blueprints/model-test/mocha-files/tests/unit/__path__/__test__.js index bf871e251a2..b1635f9b803 100644 --- a/blueprints/model-test/mocha-files/tests/unit/__path__/__test__.js +++ b/blueprints/model-test/mocha-files/tests/unit/__path__/__test__.js @@ -2,7 +2,7 @@ import { expect } from 'chai'; import { describe, it } from 'mocha'; import { setupModelTest } from 'ember-mocha'; -describe('<%= friendlyDescription %>', function() { +describe('<%= friendlyTestDescription %>', function() { setupModelTest('<%= dasherizedModuleName %>', { // Specify the other units that are required for this test. <%= typeof needs !== 'undefined' ? needs : '' %> diff --git a/blueprints/model-test/qunit-files/tests/unit/__path__/__test__.js b/blueprints/model-test/qunit-files/tests/unit/__path__/__test__.js index 8f26bfd1b67..d7d880b44a6 100644 --- a/blueprints/model-test/qunit-files/tests/unit/__path__/__test__.js +++ b/blueprints/model-test/qunit-files/tests/unit/__path__/__test__.js @@ -1,6 +1,6 @@ import { moduleForModel, test } from 'ember-qunit'; -moduleForModel('<%= dasherizedModuleName %>', '<%= friendlyDescription %>', { +moduleForModel('<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', { // Specify the other units that are required for this test. <%= typeof needs !== 'undefined' ? needs : '' %> }); diff --git a/blueprints/model-test/qunit-rfc-232-files/tests/unit/__path__/__test__.js b/blueprints/model-test/qunit-rfc-232-files/tests/unit/__path__/__test__.js new file mode 100644 index 00000000000..ea8cc022396 --- /dev/null +++ b/blueprints/model-test/qunit-rfc-232-files/tests/unit/__path__/__test__.js @@ -0,0 +1,14 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import { run } from '@ember/runloop'; + +module('model:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', function(hooks) { + setupTest(hooks); + + // Replace this with your real tests. + test('it exists', function(assert) { + let store = this.owner.lookup('service:store'); + let model = run(() => store.createRecord('<%= dasherizedModuleName %>', {})); + assert.ok(model); + }); +}); diff --git a/node-tests/blueprints/model-test.js b/node-tests/blueprints/model-test.js index e96a0016a4e..53ddf1352ab 100644 --- a/node-tests/blueprints/model-test.js +++ b/node-tests/blueprints/model-test.js @@ -16,18 +16,22 @@ const fixture = require('../helpers/fixture'); describe('Acceptance: generate and destroy model blueprints', function() { setupTestHooks(this); + beforeEach(function() { + return emberNew(); + }); + + it('model', function() { let args = ['model', 'foo']; - return emberNew() - .then(() => emberGenerateDestroy(args, _file => { + return emberGenerateDestroy(args, _file => { expect(_file('app/models/foo.js')) .to.contain('import DS from \'ember-data\';') .to.contain('export default DS.Model.extend('); expect(_file('tests/unit/models/foo-test.js')) .to.equal(fixture('model-test/foo-default.js')); - })); + }); }); it('model with attrs', function() { @@ -44,8 +48,7 @@ describe('Acceptance: generate and destroy model blueprints', function() { 'customAttr:custom-transform' ]; - return emberNew() - .then(() => emberGenerateDestroy(args, _file => { + return emberGenerateDestroy(args, _file => { expect(_file('app/models/foo.js')) .to.contain('import DS from \'ember-data\';') .to.contain('export default DS.Model.extend(') @@ -60,14 +63,13 @@ describe('Acceptance: generate and destroy model blueprints', function() { expect(_file('tests/unit/models/foo-test.js')) .to.equal(fixture('model-test/foo-default.js')); - })); + }); }); it('model with belongsTo', function() { let args = ['model', 'comment', 'post:belongs-to', 'author:belongs-to:user']; - return emberNew() - .then(() => emberGenerateDestroy(args, _file => { + return emberGenerateDestroy(args, _file => { expect(_file('app/models/comment.js')) .to.contain('import DS from \'ember-data\';') .to.contain('export default DS.Model.extend(') @@ -76,14 +78,13 @@ describe('Acceptance: generate and destroy model blueprints', function() { expect(_file('tests/unit/models/comment-test.js')) .to.equal(fixture('model-test/comment-default.js')); - })); + }); }); it('model with hasMany', function() { let args = ['model', 'post', 'comments:has-many', 'otherComments:has-many:comment']; - return emberNew() - .then(() => emberGenerateDestroy(args, _file => { + return emberGenerateDestroy(args, _file => { expect(_file('app/models/post.js')) .to.contain('import DS from \'ember-data\';') .to.contain('export default DS.Model.extend(') @@ -92,31 +93,48 @@ describe('Acceptance: generate and destroy model blueprints', function() { expect(_file('tests/unit/models/post-test.js')) .to.equal(fixture('model-test/post-default.js')); - })); + }); }); it('model-test', function() { let args = ['model-test', 'foo']; - return emberNew() - .then(() => emberGenerateDestroy(args, _file => { + return emberGenerateDestroy(args, _file => { expect(_file('tests/unit/models/foo-test.js')) .to.equal(fixture('model-test/foo-default.js')); - })); + }); }); - it('model-test for mocha v0.12+', function() { - let args = ['model-test', 'foo']; + describe('model-test with ember-cli-qunit@4.2.0', function() { + beforeEach(function() { + generateFakePackageManifest('ember-cli-qunit', '4.2.0'); + }); + + it('model-test-test foo', function() { + return emberGenerateDestroy(['model-test', 'foo'], _file => { + expect(_file('tests/unit/models/foo-test.js')) + .to.equal(fixture('model-test/rfc232.js')); + }); + }); + }); + + + describe('with ember-cli-mocha v0.12+', function() { + beforeEach(function() { + modifyPackages([ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ]); + generateFakePackageManifest('ember-cli-mocha', '0.12.0'); + }); + + it('model-test for mocha v0.12+', function() { + let args = ['model-test', 'foo']; - return emberNew() - .then(() => modifyPackages([ - {name: 'ember-cli-qunit', delete: true}, - {name: 'ember-cli-mocha', dev: true} - ])) - .then(() => generateFakePackageManifest('ember-cli-mocha', '0.12.0')) - .then(() => emberGenerateDestroy(args, _file => { + return emberGenerateDestroy(args, _file => { expect(_file('tests/unit/models/foo-test.js')) .to.equal(fixture('model-test/foo-mocha-0.12.js')); - })); + }); + }); }); }); diff --git a/node-tests/fixtures/model-test/rfc232.js b/node-tests/fixtures/model-test/rfc232.js new file mode 100644 index 00000000000..691699db857 --- /dev/null +++ b/node-tests/fixtures/model-test/rfc232.js @@ -0,0 +1,14 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; +import { run } from '@ember/runloop'; + +module('model:foo', 'Unit | Model | foo', function(hooks) { + setupTest(hooks); + + // Replace this with your real tests. + test('it exists', function(assert) { + let store = this.owner.lookup('service:store'); + let model = run(() => store.createRecord('foo', {})); + assert.ok(model); + }); +});