Skip to content

Instantly share code, notes, and snippets.

@ahmetemrekilinc
Last active October 11, 2017 13:40
Show Gist options
  • Save ahmetemrekilinc/cdc398b6cd5b49fc0003c02c280a1168 to your computer and use it in GitHub Desktop.
Save ahmetemrekilinc/cdc398b6cd5b49fc0003c02c280a1168 to your computer and use it in GitHub Desktop.
ember-service-unit-test
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Service.extend({
store: Ember.inject.service(),
setSomeProps(modelparam, idparam) {
let that = this;
this.get('store').find(modelparam, idparam)
.then((someData) => {
console.log(someData['name']);
that.set('someProp', someData['name']);
});
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
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 resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
import { moduleFor, test } from 'ember-qunit';
import wait from 'ember-test-helpers/wait';
moduleFor('service:store-caller', 'TODO: put something here', {
beforeEach:function(){
this.register('service:store', Ember.Service.extend(
{
find() {
console.log('inside mockfind');
return new Ember.RSVP.resolve({name:'abc'});
}
}
)
);
}
});
// Replace this with your real tests.
test('it exists', function(assert) {
let service = this.subject();
assert.ok(service);
});
test('test setSomeProps method', function(assert){
let service = this.subject();
assert.ok(service);
let res = service.setSomeProps('a', 'b');
return wait().then(()=>{
assert.equal(service.get('someProp'), 'abc');
});
});
{
"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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment