Skip to content

Commit

Permalink
Merge pull request #15511 from bekzod/on-fulfill
Browse files Browse the repository at this point in the history
[BUGFIX beta] possible fix for #15490
  • Loading branch information
stefanpenner authored Jul 17, 2017
2 parents cfabfc3 + 567b178 commit 8dcb2e3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/ember-testing/lib/test/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export default class TestPromise extends RSVP.Promise {
lastPromise = this;
}

then(onFulfillment, ...args) {
return super.then(result => isolate(onFulfillment, result), ...args);
then(_onFulfillment, ...args) {
let onFulfillment = typeof _onFulfillment === 'function' ?
result => isolate(_onFulfillment, result) : undefined;
return super.then(onFulfillment, ...args);
}
}

Expand Down
33 changes: 33 additions & 0 deletions packages/ember-testing/tests/ext/rsvp_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import RSVP from '../../ext/rsvp';
import { getAdapter, setAdapter } from '../../test/adapter';
import TestPromise, { getLastPromise } from '../../test/promise';
import { run } from 'ember-metal';
import { isTesting, setTesting } from 'ember-debug';

Expand Down Expand Up @@ -84,3 +85,35 @@ QUnit.test('given `Ember.testing = true`, correctly informs the test suite about
equal(asyncEnded, 2);
});
});


QUnit.module('TestPromise');

QUnit.test('does not throw error when falsy value passed to then', function() {
expect(1);
return new TestPromise(function(resolve) {
resolve()
})
.then(null)
.then(function() {
ok(true);
});
});

QUnit.test('able to get last Promise', function() {
expect(2);

var p1 = new TestPromise(function(resolve) {
resolve()
})
.then(function() {
ok(true);
});

var p2 = new TestPromise(function(resolve) {
resolve()
});

deepEqual(getLastPromise(), p2);
return p1;
});

0 comments on commit 8dcb2e3

Please sign in to comment.