-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5298 from alexander-alvarez/serializer-test
blueprints/serializer-test: Add RFC232 variants
- Loading branch information
Showing
3 changed files
with
93 additions
and
28 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
blueprints/serializer-test/qunit-rfc-232-files/tests/unit/__path__/__test__.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
import { run } from '@ember/runloop'; | ||
|
||
module('<%= friendlyTestDescription %>', function(hooks) { | ||
setupTest(hooks); | ||
|
||
// Replace this with your real tests. | ||
test('it exists', function(assert) { | ||
let store = this.owner.lookup('service:store'); | ||
let serializer = store.serializerFor('<%= dasherizedModuleName %>'); | ||
|
||
assert.ok(serializer); | ||
}); | ||
|
||
test('it serializes records', function(assert) { | ||
let store = this.owner.lookup('service:store'); | ||
let record = run(() => store.createRecord('<%= dasherizedModuleName %>', {})); | ||
|
||
let serializedRecord = record.serialize(); | ||
|
||
assert.ok(serializedRecord); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,25 +18,28 @@ const fixture = require('../helpers/fixture'); | |
describe('Acceptance: generate and destroy serializer blueprints', function() { | ||
setupTestHooks(this); | ||
|
||
|
||
beforeEach(function() { | ||
return emberNew(); | ||
}); | ||
|
||
it('serializer', function() { | ||
let args = ['serializer', 'foo']; | ||
|
||
return emberNew() | ||
.then(() => emberGenerateDestroy(args, _file => { | ||
return emberGenerateDestroy(args, _file => { | ||
expect(_file('app/serializers/foo.js')) | ||
.to.contain('import DS from \'ember-data\';') | ||
.to.contain('export default DS.JSONAPISerializer.extend('); | ||
|
||
expect(_file('tests/unit/serializers/foo-test.js')) | ||
.to.equal(fixture('serializer-test/foo-default.js')); | ||
})); | ||
}); | ||
}); | ||
|
||
it('serializer extends application serializer if it exists', function() { | ||
let args = ['serializer', 'foo']; | ||
|
||
return emberNew() | ||
.then(() => emberGenerate(['serializer', 'application'])) | ||
return emberGenerate(['serializer', 'application']) | ||
.then(() => emberGenerateDestroy(args, _file => { | ||
expect(_file('app/serializers/foo.js')) | ||
.to.contain('import ApplicationSerializer from \'./application\';') | ||
|
@@ -50,61 +53,75 @@ describe('Acceptance: generate and destroy serializer blueprints', function() { | |
it('serializer with --base-class', function() { | ||
let args = ['serializer', 'foo', '--base-class=bar']; | ||
|
||
return emberNew() | ||
.then(() => emberGenerateDestroy(args, _file => { | ||
return emberGenerateDestroy(args, _file => { | ||
expect(_file('app/serializers/foo.js')) | ||
.to.contain('import BarSerializer from \'./bar\';') | ||
.to.contain('export default BarSerializer.extend({'); | ||
|
||
expect(_file('tests/unit/serializers/foo-test.js')) | ||
.to.equal(fixture('serializer-test/foo-default.js')); | ||
})); | ||
}); | ||
}); | ||
|
||
xit('serializer throws when --base-class is same as name', function() { | ||
let args = ['serializer', 'foo', '--base-class=foo']; | ||
|
||
return emberNew() | ||
.then(() => expect(emberGenerate(args)) | ||
.to.be.rejectedWith(SilentError, /Serializers cannot extend from themself/)); | ||
return expect(emberGenerate(args)) | ||
.to.be.rejectedWith(SilentError, /Serializers cannot extend from themself/); | ||
}); | ||
|
||
it('serializer when is named "application"', function() { | ||
let args = ['serializer', 'application']; | ||
|
||
return emberNew() | ||
.then(() => emberGenerateDestroy(args, _file => { | ||
return emberGenerateDestroy(args, _file => { | ||
expect(_file('app/serializers/application.js')) | ||
.to.contain('import DS from \'ember-data\';') | ||
.to.contain('export default DS.JSONAPISerializer.extend({'); | ||
|
||
expect(_file('tests/unit/serializers/application-test.js')) | ||
.to.equal(fixture('serializer-test/application-default.js')); | ||
})); | ||
}); | ||
}); | ||
|
||
it('serializer-test', function() { | ||
let args = ['serializer-test', 'foo']; | ||
|
||
return emberNew() | ||
.then(() => emberGenerateDestroy(args, _file => { | ||
return emberGenerateDestroy(args, _file => { | ||
expect(_file('tests/unit/serializers/foo-test.js')) | ||
.to.equal(fixture('serializer-test/foo-default.js')); | ||
})); | ||
}); | ||
}); | ||
|
||
it('serializer-test for mocha v0.12+', function() { | ||
let args = ['serializer-test', 'foo']; | ||
describe('serializer-test with [email protected]', function() { | ||
beforeEach(function() { | ||
generateFakePackageManifest('ember-cli-qunit', '4.2.0'); | ||
}); | ||
|
||
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 => { | ||
it('serializer-test-test foo', function() { | ||
return emberGenerateDestroy(['serializer-test', 'foo'], _file => { | ||
expect(_file('tests/unit/serializers/foo-test.js')) | ||
.to.equal(fixture('serializer-test/foo-mocha-0.12.js')); | ||
})); | ||
.to.equal(fixture('serializer-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('serializer-test for mocha v0.12+', function() { | ||
let args = ['serializer-test', 'foo']; | ||
|
||
return emberGenerateDestroy(args, _file => { | ||
expect(_file('tests/unit/serializers/foo-test.js')) | ||
.to.equal(fixture('serializer-test/foo-mocha-0.12.js')); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
import { run } from '@ember/runloop'; | ||
|
||
module('Unit | Serializer | foo', function(hooks) { | ||
setupTest(hooks); | ||
|
||
// Replace this with your real tests. | ||
test('it exists', function(assert) { | ||
let store = this.owner.lookup('service:store'); | ||
let serializer = store.serializerFor('foo'); | ||
|
||
assert.ok(serializer); | ||
}); | ||
|
||
test('it serializes records', function(assert) { | ||
let store = this.owner.lookup('service:store'); | ||
let record = run(() => store.createRecord('foo', {})); | ||
|
||
let serializedRecord = record.serialize(); | ||
|
||
assert.ok(serializedRecord); | ||
}); | ||
}); |