Skip to content

Instantly share code, notes, and snippets.

@ultimatemonty
Last active March 23, 2017 14:56
Show Gist options
  • Save ultimatemonty/4db6f5e6e7d92b11bceac1a06cfffa09 to your computer and use it in GitHub Desktop.
Save ultimatemonty/4db6f5e6e7d92b11bceac1a06cfffa09 to your computer and use it in GitHub Desktop.
ember-data async testing issue
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { hasMany } from "ember-data/relationships";
export default Model.extend({
name: attr('string'),
sources: hasMany('source', { async: false })
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo } from "ember-data/relationships";
export default Model.extend({
name: attr('string'),
nurture: belongsTo('nurture', { async: false })
});
import RESTSerializer from 'ember-data/serializers/rest';
import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin';
export default RESTSerializer.extend(EmbeddedRecordsMixin, {
attrs: {
sources: { embedded: 'always' }
}
});
import RESTSerializer from 'ember-data/serializers/rest';
import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin';
export default RESTSerializer.extend(EmbeddedRecordsMixin, {
attrs: {
name: { serialize: false }
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
const { run } = Ember;
const assign = Ember.assign || Ember.merge;
export default function startApp(attrs) {
let application;
let attributes = assign({rootElement: "#test-root"}, config.APP);
attributes = assign(attributes, attrs); // use defaults, but you can override;
run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
import { moduleForModel, test } from 'ember-qunit';
moduleForModel('source', 'Unit | Serializer | source', {
beforeEach: function() {
this.server = new Pretender(function() {
this.get('/sources', function() {
let sources = [{
id: 1,
name: 'test source',
nurture_id: 1
}];
let response = { sources: sources };
return [200, { "Content-Type": "application/json" }, JSON.stringify(response)];
});
this.get('/nurtures/:id', function(request) {
let nurture = {
id: 1,
name: 'test workflow',
sources: [{
id: 1,
name: 'test source',
nurture_id: 1
}]
}
let response = { nurture: nurture };
return [200, { "Content-Type": "application/json" }, JSON.stringify(response)];
});
});
},
afterEach: function() {
this.server.shutdown();
},
needs: [ 'serializer:source', 'model:nurture', 'serializer:nurture']
});
// Replace this with your real tests.
test('it exists', function(assert) {
let controller = this.subject();
assert.ok(controller);
});
{
"version": "0.12.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.9.1",
"ember-template-compiler": "2.9.1",
"ember-data": "2.11.3",
"ember-testing": "2.9.1",
"FakeXMLHttpRequest": "https://rawgit.com/pretenderjs/FakeXMLHttpRequest/23c3a96b5b24f1bfe595867437e4f128a29c2840/fake_xml_http_request.js",
"pretender": "https://rawgit.com/pretenderjs/pretender/c6de9afe18b1472aded2592f5a80ad9a26a0e262/pretender.js"
},
"addons": {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment