Skip to content

Commit

Permalink
Add two failing tests for returning null and then a promise proxy
Browse files Browse the repository at this point in the history
- The first new test fails with an error
- The second test will just lock up the test runner.
  • Loading branch information
scottmessinger committed Jun 5, 2019
1 parent 0017138 commit e349e96
Showing 1 changed file with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { EMBER_METAL_TRACKED_PROPERTIES } from '@ember/canary-features';
import { Object as EmberObject, ArrayProxy, PromiseProxyMixin } from '@ember/-internals/runtime';
import {
Object as EmberObject,
ArrayProxy,
ObjectProxy,
PromiseProxyMixin,
} from '@ember/-internals/runtime';
import { later } from '@ember/runloop';
import { set } from '@ember/-internals/metal';
import { tracked, nativeDescDecorator as descriptor } from '@ember/-internals/metal';
import { Promise } from 'rsvp';
import { moduleFor, RenderingTestCase, strip, runTask } from 'internal-test-helpers';
Expand Down Expand Up @@ -45,6 +52,82 @@ if (EMBER_METAL_TRACKED_PROPERTIES) {
this.assertText('max jackson | max jackson');
}

'@test returning null and then later a Promise in un-memoized getter does not cause Maximum call stack size exceeded'(
assert
) {
let ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin);
let done = assert.async();

class LoaderComponent extends GlimmerishComponent {
get data() {
if (this.args.id === null) {
return null;
} else {
let promise = new Promise((resolve, reject) => {
resolve(this.args.id);
});
return ObjectPromiseProxy.create({ promise: promise });
}
}
}

this.registerComponent('loader', {
ComponentClass: LoaderComponent,
template: '{{this.data.isPending}} {{this.data.isFulfilled}} {{this.data.content}}',
});

this.render('<Loader @id={{id}}/>', {
id: null,
});

setTimeout(() => {
this.context.set('id', 'one');
done();
}, 200);

this.assertText('true false one');
}

'@test returning null and then later a Promise in un-memoized getter does not cause perpetual rerenders'(
assert
) {
let ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin);
let done = assert.async();

class LoaderComponent extends GlimmerishComponent {
async anAsyncFunction(id) {
let result = await new Promise((resolve, reject) => {
resolve(this.args.id);
});
return result;
}

get data() {
if (this.args.id === null) {
return null;
} else {
return ObjectPromiseProxy.create({ promise: this.anAsyncFunction(this.args.id) });
}
}
}

this.registerComponent('loader', {
ComponentClass: LoaderComponent,
template: '{{this.data.isPending}} {{this.data.isFulfilled}} {{this.data.content}}',
});

this.render('<Loader @id={{id}}/>', {
id: null,
});

setTimeout(() => {
this.context.set('id', 'one');
done();
}, 200);

this.assertText('true false one');
}

'@test returning ArrayProxy in un-memoized getter does not cause perpetual rerenders'() {
let PromiseArray = ArrayProxy.extend(PromiseProxyMixin);

Expand Down

0 comments on commit e349e96

Please sign in to comment.