Skip to content

Commit

Permalink
adding friendly asserting when you forget to needs a transform in uni…
Browse files Browse the repository at this point in the history
…t test
  • Loading branch information
danielspaniel committed Feb 2, 2017
1 parent 37512ed commit 881af9b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions addon/converter/fixture-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ export default class {
return this.defaultValueTransformFn;
}
let container = Ember.getOwner ? Ember.getOwner(this.store) : this.store.container;
let transform = container.lookup('transform:' + type);

Ember.assert(`[ember-data-factory-guy] could not find
the [ ${type} ] transform. If you are in a unit test, be sure
to include it in the list of needs as [ transform:${type} ], Or set your
unit test to be [ integration: true ] and include everything.`,
transform
);

return container.lookup('transform:' + type).serialize;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/unit/router-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {mockFindAll, mockSetup, mockTeardown, manualSetup} from 'ember-data-factory-guy';
import {moduleFor, test} from 'ember-qunit';

moduleFor('route:profiles', 'Unit | forgetting to needs transform', {
beforeEach() {
manualSetup(this.container);
},

afterEach() {
mockTeardown();
},

needs: [
'model:profile',
// 'transform:just-a-string' ( it's common to forget this needs )
]
});

test('profiles', function(assert) {
let regex = new RegExp("\\[ember-data-factory-guy\\] could not find\\s*the \\[ just-a-string \\] transform");
assert.throws(
()=>mockFindAll('profile', 2),
(err)=>{
return regex.test(err.toString());
});
});

0 comments on commit 881af9b

Please sign in to comment.