Skip to content

Instantly share code, notes, and snippets.

@cs3b
Last active January 14, 2019 09:50
Show Gist options
  • Save cs3b/14e543224d3349ec30cab38fc77b6e09 to your computer and use it in GitHub Desktop.
Save cs3b/14e543224d3349ec30cab38fc77b6e09 to your computer and use it in GitHub Desktop.
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();
}
});
import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
export default Model.extend({
});
export default function(server) {
server.createList('user', 5);
}
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({
name: attr()
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findAll('user');
}
});
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>
</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.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment