Skip to content

Instantly share code, notes, and snippets.

@timhaines timhaines/mirage.config.js
Last active Apr 16, 2017

Embed
What would you like to do?
Mirage Dev Boilerplate
export default function() {
//window.server = this;
this.get('users');
};
import { Factory, faker, trait } from 'ember-cli-mirage';
export default Factory.extend({
name() {
return faker.name.findName();
},
afterCreate(user, server) {
if (!user.post) {
let post = server.create('post', {user: user});
user.update({post});
}
},
});
import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
export default Model.extend({
user: belongsTo()
});
import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
export default Model.extend({
post: belongsTo()
});
export default function(server) {
let user1 = server.create('user');
}
import { JSONAPISerializer } from 'ember-cli-mirage';
export default JSONAPISerializer.extend({
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
user: belongsTo()
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
name: attr(),
post: belongsTo()
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('user', { include: 'post' });
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
h1 {
font-size: 12px;
font-weight: bold;
text-align: center;
text-shadow: none;
background: #2e4068;
color: white;
padding: 20px;
margin: 0;
text-transform: uppercase;
}
p {
font-weight: normal;
}
.pa4 {
padding: 20px;
}
<h1>Mirage boilerplate</h1>
<div class='pa4'>
{{#each model as |user|}}
<p class='user-name'>
I am <strong>{{user.name}}</strong>.
I have {{user.post.id }} posts.
</p>
{{/each}}
</div>
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import { module } from 'qunit';
import Ember from 'ember';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
const { RSVP: { Promise } } = Ember;
export default function(name, options = {}) {
module(name, {
beforeEach() {
this.application = startApp();
if (options.beforeEach) {
return options.beforeEach.apply(this, arguments);
}
},
afterEach() {
let afterEach = options.afterEach && options.afterEach.apply(this, arguments);
return Promise.resolve(afterEach).then(() => destroyApp(this.application));
}
});
}
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);
{
"version": "0.12.1",
"ENV": {
"ember-cli-mirage": {
"enabled": true
}
},
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1",
"ember-cli-mirage": "0.3.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.