Last active
September 28, 2017 20:46
-
-
Save jlami/6714d1ff03d0d1893d0bea6e571ae0d3 to your computer and use it in GitHub Desktop.
Action promise ignored
This file contains hidden or 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', | |
| actions: { | |
| moveOn() { | |
| return new Ember.RSVP.Promise((resolve, reject) => { | |
| //should work with any async callback | |
| setTimeout(resolve, 1000); | |
| //the following does work | |
| //Ember.run.later(resolve, 1000); | |
| //But addons/npm packages should not be expected to use ember run | |
| }) | |
| //bubbling is not supported yet | |
| //.then(() => console.log('step 1 done')) | |
| //.then(() => true) | |
| .then(() => this.transitionToRoute('should-endup-here')); | |
| ; | |
| }, | |
| }, | |
| }); |
This file contains hidden or 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'; | |
| let waiter = null; | |
| Ember.Test.registerAsyncHelper('waitForActions', function() { | |
| return waiter.then(() => console.log('done?'));//does not work with bubbling right now? | |
| }); | |
| export default { | |
| name: 'action-waiter', | |
| initialize() { | |
| if (Ember.testing) { | |
| Ember.ActionHandler.reopen({ | |
| send(actionName, ...args) { | |
| console.log(actionName); | |
| return waiter = Ember.RSVP.resolve(this.actions && this.actions[actionName] && this.actions[actionName].apply(this, args) || true) | |
| .then(result => { | |
| let shouldBubble = result === true; | |
| if (!shouldBubble) { return; } | |
| let target = Ember.get(this, 'target'); | |
| if (target) { | |
| Ember.assert( | |
| `The \`target\` for ${this} (${target}) does not have a \`send\` method`, | |
| typeof target.send === 'function' | |
| ); | |
| return target.send(...arguments); | |
| } | |
| }); | |
| }, | |
| }); | |
| } | |
| }, | |
| }; |
This file contains hidden or 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'; | |
| import config from './config/environment'; | |
| const Router = Ember.Router.extend({ | |
| location: 'none', | |
| rootURL: config.rootURL | |
| }); | |
| Router.map(function() { | |
| this.route('start'); | |
| this.route('should-endup-here'); | |
| }); | |
| export default Router; |
This file contains hidden or 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.Route.extend({ | |
| actions: { | |
| moveOn() { | |
| console.log('bubbling'); | |
| return new Ember.RSVP.Promise((resolve, reject) => { | |
| //should work with any async callback | |
| setTimeout(resolve, 1000); | |
| //the following does work | |
| //Ember.run.later(resolve, 1000); | |
| //But addons/npm packages should not be expected to use ember run | |
| }) | |
| .then(() => this.transitionTo('should-endup-here')); | |
| }, | |
| }, | |
| }); |
This file contains hidden or 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 { test } from 'qunit'; | |
| import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; | |
| moduleForAcceptance('Click should wait for promise'); | |
| test('visiting /wait-for-action', function(assert) { | |
| visit('/start'); | |
| click('button'); | |
| waitForActions(); | |
| andThen(function() { | |
| assert.equal(currentURL(), '/should-endup-here'); | |
| }); | |
| }); |
This file contains hidden or 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 function destroyApp(application) { | |
| Ember.run(application, 'destroy'); | |
| } |
This file contains hidden or 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 { module } from 'qunit'; | |
| import Ember from 'ember'; | |
| import startApp from '../helpers/start-app'; | |
| import destroyApp from '../helpers/destroy-app'; | |
| const { RSVP: { Promise } } = Ember; | |
| export default function(name, options = {}) { | |
| module(name, { | |
| beforeEach() { | |
| this.application = startApp(); | |
| if (options.beforeEach) { | |
| return options.beforeEach.apply(this, arguments); | |
| } | |
| }, | |
| afterEach() { | |
| let afterEach = options.afterEach && options.afterEach.apply(this, arguments); | |
| return Promise.resolve(afterEach).then(() => destroyApp(this.application)); | |
| } | |
| }); | |
| } |
This file contains hidden or 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 hidden or 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'; | |
| 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; | |
| } |
This file contains hidden or 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 hidden or 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.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