Skip to content

Instantly share code, notes, and snippets.

@lolmaus
Last active September 10, 2015 12:38
Show Gist options
  • Save lolmaus/16c095d1c104cede9cd6 to your computer and use it in GitHub Desktop.
Save lolmaus/16c095d1c104cede9cd6 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
import StartExamMixin from '../../../mixins/start-exam';
import { module, test } from 'qunit';
import sinon from 'sinon';
const {
RSVP,
ActionHandler
} = Ember;
module('Unit | Mixin | start exam');
test('action start', function(assert) {
assert.expect(3);
let spy, resolve;
const exam = {
createExamSession() {
return new RSVP.Promise((res) => { resolve = res; });
}
};
const StartExamObject = Ember.Object.extend(ActionHandler, StartExamMixin, {
attrs: {
actionTransitionToSession: spy = sinon.spy()
}
});
const subject = StartExamObject.create();
const done = assert.async();
const promiseWaiter = (prm) => {
prm.then(() => {
assert.ok(spy.calledOnce);
assert.ok(spy.calledWith('foo'));
done();
});
};
subject.send('start', exam, promiseWaiter);
assert.ok(spy.notCalled);
resolve({id: 'foo'});
});
import Ember from 'ember';
import _ from 'npm:lodash';
export default Ember.Mixin.create({
actions: {
start(exam, promiseWaiter) {
const prm =
exam
.createExamSession()
.then((session) => {
this.attrs.actionTransitionToSession(session.id);
});
if (_.isFunction(promiseWaiter)) {
promiseWaiter(prm);
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment