Skip to content

Commit cbc8b7f

Browse files
committed
Merge branch 'master' into auxillary-refactors
2 parents 563f9ce + 778eb78 commit cbc8b7f

3 files changed

Lines changed: 46 additions & 18 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { setupModelTest } from 'ember-mocha';
4+
5+
describe('Unit | Model | rental', function() {
6+
setupModelTest('rental', {
7+
needs: []
8+
});
9+
// Replace this with your real tests.
10+
it('exists', function() {
11+
let model = this.subject();
12+
expect(model).to.be.ok;
13+
});
14+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { setupTest } from 'ember-mocha';
4+
5+
describe('Unit | Model | rental', function() {
6+
setupTest();
7+
// Replace this with your real tests.
8+
it('exists', function() {
9+
let model = this.owner.lookup('service:store').createRecord('rental', {});
10+
expect(model).to.be.ok;
11+
});
12+
});

fourteen-testing-api.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = function(file, api) {
44
const j = api.jscodeshift;
55
const root = j(file.source);
66

7-
const SETUP_TYPE_METHODS = ["setupComponentTest"];
7+
const SETUP_TYPE_METHODS = ["setupComponentTest", "setupModelTest"];
88

99
function isSetupTypeMethod(nodePath) {
1010
return SETUP_TYPE_METHODS.some(name => {
@@ -192,6 +192,9 @@ module.exports = function(file, api) {
192192
this.setupType = "setupTest";
193193
this.subjectContainerKey = j.literal(`component:${node.expression.arguments[0].value}`);
194194
}
195+
} else if (calleeName === 'setupModelTest') {
196+
this.setupType = 'setupTest';
197+
this.modelName = node.expression.arguments[0].value;
195198
}
196199

197200
this.setupTypeMethodInvocationNode = node.expression;
@@ -458,9 +461,16 @@ module.exports = function(file, api) {
458461

459462
thisDotSubjectUsage.forEach(p => {
460463
let options = p.node.arguments[0];
461-
let split = subject.value.split(':');
462-
let subjectType = split[0];
463-
let subjectName = split[1];
464+
let subjectType;
465+
let subjectName;
466+
if ('modelName' in moduleInfo) {
467+
subjectType = 'model';
468+
subjectName = moduleInfo.modelName;
469+
} else {
470+
let split = subject.value.split(':');
471+
subjectType = split[0];
472+
subjectName = split[1];
473+
}
464474
let isSingletonSubject = ['model', 'component'].indexOf(subjectType) === -1;
465475

466476
// if we don't have `options` and the type is a singleton type
@@ -476,15 +486,7 @@ module.exports = function(file, api) {
476486
)
477487
);
478488
} else if (subjectType === 'model') {
479-
ensureImportWithSpecifiers({
480-
source: '@ember/runloop',
481-
specifiers: ['run'],
482-
});
483-
484489
p.replace(
485-
j.callExpression(j.identifier('run'), [
486-
j.arrowFunctionExpression(
487-
[],
488490
j.callExpression(
489491
j.memberExpression(
490492
j.callExpression(
@@ -496,11 +498,10 @@ module.exports = function(file, api) {
496498
),
497499
j.identifier('createRecord')
498500
),
499-
[j.literal(subjectName), options].filter(Boolean)
500-
),
501-
true
502-
),
503-
])
501+
// creating an empty object expression {} as the 2nd argument here
502+
// because setupModelTests shouldn't need store dependencies
503+
[j.literal(subjectName), j.objectExpression([])].filter(Boolean)
504+
)
504505
);
505506
} else {
506507
p.replace(
@@ -630,7 +631,8 @@ module.exports = function(file, api) {
630631

631632
function updateToNewEmberMochaImports() {
632633
let mapping = {
633-
setupComponentTest: "setupRenderingTest"
634+
setupComponentTest: "setupRenderingTest",
635+
setupModelTest: "setupTest"
634636
};
635637

636638
let emberMochaImports = root.find(j.ImportDeclaration, { source: { value: "ember-mocha" } });

0 commit comments

Comments
 (0)