Created
March 21, 2016 19:50
-
-
Save robbiespeed/50df37b8c7c2283413b9 to your computer and use it in GitHub Desktop.
Async Service Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
text: DS.attr('string') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const { RSVP } = Ember; | |
export default Ember.Service.extend({ | |
store: Ember.inject.service(), | |
loggedIn: null, | |
name: null, | |
message: null, | |
signIn (data) { | |
return new RSVP.Promise((resolve) => { | |
this._parseSignIn(data); | |
resolve(); | |
}); | |
}, | |
signOut (data) { | |
return new RSVP.Promise((resolve) => { | |
this._reset(); | |
resolve(); | |
}); | |
}, | |
_parseSignIn (data) { | |
this.set('loggedIn', true); | |
this.set('name', data.name); | |
this.set('message', this.get('store').createRecord('message', { | |
text: data.message, | |
})); | |
}, | |
_reset () { | |
this.set('loggedIn', null); | |
this.set('name', null); | |
this.set('message', null); | |
this.get('store').unloadAll(); | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
setResolver(resolver); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { moduleFor, test } from 'ember-qunit'; | |
import Ember from 'ember'; | |
const { run, RSVP } = Ember; | |
moduleFor('service:user', 'Unit | Service | user', { | |
// Specify the other units that are required for this test. | |
needs: ['model:message'] | |
}); | |
test('exists', function(assert) { | |
const user = this.subject(); | |
assert.ok(user); | |
}); | |
test('can sign-out', function (assert) { | |
return new RSVP.Promise((resolve/*, reject*/) => { | |
const user = this.subject(); | |
user.set('loggedIn', true); | |
user.signOut().finally(() => { | |
assert.ok(!user.get('loggedIn')); | |
resolve(); | |
}); | |
}); | |
}); | |
test('can sign-in', function(assert) { | |
return new RSVP.Promise((resolve/*, reject*/) => { | |
const user = this.subject(); | |
user.signOut().finally(() => { | |
user.signIn({ | |
name: 'Jim', | |
message: 'Hello World' | |
}).finally(() => { | |
assert.equal(user.get('name'), 'Jim'); | |
resolve(); | |
}); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.6.5", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"enable-testing": true | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.4.3", | |
"ember-data": "2.4.0", | |
"ember-template-compiler": "2.4.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment