Skip to content

Commit 7055559

Browse files
committed
Add controller-test generator.
1 parent 889a108 commit 7055559

File tree

10 files changed

+224
-0
lines changed

10 files changed

+224
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
const stringUtil = require('ember-cli-string-utils');
4+
5+
const useTestFrameworkDetector = require('../test-framework-detector');
6+
7+
module.exports = useTestFrameworkDetector({
8+
description: 'Generates a controller unit test.',
9+
locals: function(options) {
10+
let dasherizedModuleName = stringUtil.dasherize(options.entity.name);
11+
let controllerPathName = dasherizedModuleName;
12+
return {
13+
controllerPathName: controllerPathName,
14+
friendlyTestDescription: ['Unit', 'Controller', dasherizedModuleName].join(' | ')
15+
};
16+
}
17+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { setupTest } from 'ember-mocha';
4+
5+
describe('<%= friendlyTestDescription %>', function() {
6+
setupTest('controller:<%= dasherizedModuleName %>', {
7+
// Specify the other units that are required for this test.
8+
// needs: ['controller:foo']
9+
});
10+
11+
// Replace this with your real tests.
12+
it('exists', function() {
13+
let controller = this.subject();
14+
expect(controller).to.be.ok;
15+
});
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from 'chai';
2+
import { describeModule, it } from 'ember-mocha';
3+
4+
describeModule('controller:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>',
5+
{
6+
// Specify the other units that are required for this test.
7+
// needs: ['controller:foo']
8+
},
9+
function() {
10+
// Replace this with your real tests.
11+
it('exists', function() {
12+
let controller = this.subject();
13+
expect(controller).to.be.ok;
14+
});
15+
}
16+
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { moduleFor, test } from 'ember-qunit';
2+
3+
moduleFor('controller:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', {
4+
// Specify the other units that are required for this test.
5+
// needs: ['controller:foo']
6+
});
7+
8+
// Replace this with your real tests.
9+
test('it exists', function(assert) {
10+
let controller = this.subject();
11+
assert.ok(controller);
12+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
module('<%= friendlyTestDescription %>', function(hooks) {
5+
setupTest(hooks);
6+
7+
// Replace this with your real tests.
8+
test('it exists', function(assert) {
9+
let controller = this.owner.lookup('controller:<%= controllerPathName %>');
10+
assert.ok(controller);
11+
});
12+
});
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
'use strict';
2+
3+
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
4+
const setupTestHooks = blueprintHelpers.setupTestHooks;
5+
const emberNew = blueprintHelpers.emberNew;
6+
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
7+
const modifyPackages = blueprintHelpers.modifyPackages;
8+
9+
const chai = require('ember-cli-blueprint-test-helpers/chai');
10+
const expect = chai.expect;
11+
12+
const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
13+
const fixture = require('../helpers/fixture');
14+
15+
describe('Blueprint: controller-test', function() {
16+
setupTestHooks(this);
17+
18+
describe('in app', function() {
19+
beforeEach(function() {
20+
return emberNew();
21+
});
22+
23+
it('controller-test foo', function() {
24+
return emberGenerateDestroy(['controller-test', 'foo'], _file => {
25+
expect(_file('tests/unit/controllers/foo-test.ts')).to.equal(
26+
fixture('controller-test/default.ts')
27+
);
28+
});
29+
});
30+
31+
describe('with ember-cli-qunit@4.2.0', function() {
32+
beforeEach(function() {
33+
generateFakePackageManifest('ember-cli-qunit', '4.2.0');
34+
});
35+
36+
it('controller-test foo', function() {
37+
return emberGenerateDestroy(['controller-test', 'foo'], _file => {
38+
expect(_file('tests/unit/controllers/foo-test.ts')).to.equal(
39+
fixture('controller-test/rfc232.ts')
40+
);
41+
});
42+
});
43+
});
44+
45+
describe('with ember-cli-mocha@0.11.0', function() {
46+
beforeEach(function() {
47+
modifyPackages([
48+
{ name: 'ember-cli-qunit', delete: true },
49+
{ name: 'ember-cli-mocha', dev: true },
50+
]);
51+
generateFakePackageManifest('ember-cli-mocha', '0.11.0');
52+
});
53+
54+
it('controller-test foo for mocha', function() {
55+
return emberGenerateDestroy(['controller-test', 'foo'], _file => {
56+
expect(_file('tests/unit/controllers/foo-test.ts')).to.equal(
57+
fixture('controller-test/mocha.ts')
58+
);
59+
});
60+
});
61+
});
62+
63+
describe('with ember-cli-mocha@0.12.0', function() {
64+
beforeEach(function() {
65+
modifyPackages([
66+
{ name: 'ember-cli-qunit', delete: true },
67+
{ name: 'ember-cli-mocha', dev: true },
68+
]);
69+
generateFakePackageManifest('ember-cli-mocha', '0.12.0');
70+
});
71+
72+
it('controller-test foo', function() {
73+
return emberGenerateDestroy(['controller-test', 'foo'], _file => {
74+
expect(_file('tests/unit/controllers/foo-test.ts')).to.equal(
75+
fixture('controller-test/mocha-0.12.ts')
76+
);
77+
});
78+
});
79+
});
80+
});
81+
82+
describe('in addon', function() {
83+
beforeEach(function() {
84+
return emberNew({ target: 'addon' });
85+
});
86+
87+
it('controller-test foo', function() {
88+
return emberGenerateDestroy(['controller-test', 'foo'], _file => {
89+
expect(_file('tests/unit/controllers/foo-test.ts')).to.equal(
90+
fixture('controller-test/default.ts')
91+
);
92+
});
93+
});
94+
});
95+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { moduleFor, test } from 'ember-qunit';
2+
3+
moduleFor('controller:foo', 'Unit | Controller | foo', {
4+
// Specify the other units that are required for this test.
5+
// needs: ['controller:foo']
6+
});
7+
8+
// Replace this with your real tests.
9+
test('it exists', function(assert) {
10+
let controller = this.subject();
11+
assert.ok(controller);
12+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { setupTest } from 'ember-mocha';
4+
5+
describe('Unit | Controller | foo', function() {
6+
setupTest('controller:foo', {
7+
// Specify the other units that are required for this test.
8+
// needs: ['controller:foo']
9+
});
10+
11+
// Replace this with your real tests.
12+
it('exists', function() {
13+
let controller = this.subject();
14+
expect(controller).to.be.ok;
15+
});
16+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from 'chai';
2+
import { describeModule, it } from 'ember-mocha';
3+
4+
describeModule('controller:foo', 'Unit | Controller | foo',
5+
{
6+
// Specify the other units that are required for this test.
7+
// needs: ['controller:foo']
8+
},
9+
function() {
10+
// Replace this with your real tests.
11+
it('exists', function() {
12+
let controller = this.subject();
13+
expect(controller).to.be.ok;
14+
});
15+
}
16+
);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
module('Unit | Controller | foo', function(hooks) {
5+
setupTest(hooks);
6+
7+
// Replace this with your real tests.
8+
test('it exists', function(assert) {
9+
let controller = this.owner.lookup('controller:foo');
10+
assert.ok(controller);
11+
});
12+
});

0 commit comments

Comments
 (0)