Skip to content

Instantly share code, notes, and snippets.

@samselikoff
Forked from Gaurav0/components.my-component.js
Last active July 15, 2016 05:08
Show Gist options
  • Save samselikoff/523f22c8104d702d48b5fcc9be7ad583 to your computer and use it in GitHub Desktop.
Save samselikoff/523f22c8104d702d48b5fcc9be7ad583 to your computer and use it in GitHub Desktop.
Mirage Sandbox
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
export default function() {
this.get('assets/:id');
};
import Mirage from 'ember-cli-mirage';
export default Mirage.Factory.extend({
});
import Mirage from 'ember-cli-mirage';
export default Mirage.Factory.extend({
});
import Mirage from 'ember-cli-mirage';
export default Mirage.Factory.extend({
name: function(i) {
return 'User ' + i
}
});
import { Model, belongsTo, hasMany } from 'ember-cli-mirage';
export default Model.extend({
});
import { Model } from 'ember-cli-mirage';
export default Model.extend({
});
export default function(server) {
// added this line because global wasn't created otherwise.
window.server = server;
server.create('asset', { title: 'Asset title' });
}
import { JSONAPISerializer } from 'ember-cli-mirage';
export default JSONAPISerializer;
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr(),
image: DS.belongsTo(),
images: DS.hasMany()
});
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr()
});
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string')
});
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.store.findRecord('asset', 1);
}
});
import DS from 'ember-data';
export default DS.JSONAPISerializer.extend();
<h1>Welcome to {{appName}}</h1>
<h2>The title is {{model.title}}</h2>
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
moduleForAcceptance('Visiting application');
test('visiting /', function(assert) {
visit('/');
andThen(function() {
assert.equal(currentURL(), '/');
// #root is required because application is also running under test
// any way to avoid this?
assert.equal($('#root li.user-name').length, 10);
});
});
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import { module } from 'qunit';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
export default function(name, options = {}) {
module(name, {
beforeEach() {
this.application = startApp();
if (options.beforeEach) {
options.beforeEach.apply(this, arguments);
}
},
afterEach() {
if (options.afterEach) {
options.afterEach.apply(this, arguments);
}
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';
export default function startApp(attrs) {
let application;
let attributes = Ember.merge({rootElement: "#test-root"}, config.APP);
attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;
Ember.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.7.2",
"ENV": {
"ember-cli-mirage": {
"enabled": true,
"directory": "app/mirage"
}
},
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js"
},
"addons": {
"ember-cli-mirage": "0.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment