Skip to content

Instantly share code, notes, and snippets.

@ykaragol
Created October 17, 2016 20:23
Show Gist options
  • Save ykaragol/7b868c31e43064c20f6e95991a53f353 to your computer and use it in GitHub Desktop.
Save ykaragol/7b868c31e43064c20f6e95991a53f353 to your computer and use it in GitHub Desktop.
store-stubbing
import Ember from 'ember';
export default Ember.Component.extend({
store:Ember.inject.service(),
actions: {
loadPartners() {
let self = this; this.get('store').findAll('partner').then(function(partners) {
self.set('partners', partners);
});
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
<button {{action "loadPartners"}}>Are you sure?</button>
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 { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
const StoreStub = Ember.Service.extend({
findAll:function(){
return new Ember.RSVP.Promise(function(resolve){
resolve();
});
}
});
moduleForComponent('my-component', 'stub test', {
integration: true,
beforeEach:function(){
this.register('service:store', StoreStub);
this.inject.service('store');
}
});
test('it renders', function(assert) {
this.render(hbs`{{my-component}}`);
this.$('button').click();
assert.equal(this.$().text().trim(), 'Are you sure?');
});
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.10.5",
"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.8.0",
"ember-data": "2.8.0",
"ember-template-compiler": "2.8.0",
"ember-testing": "2.8.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment