Skip to content

Commit

Permalink
Update tests (which worked as they should!)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskrycho committed Sep 4, 2021
1 parent eb78f04 commit 8e67fac
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion tests/unit/helpers/load-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module("Unit | load", function (hooks) {
});

test("given a plain value", async function (assert) {
const result = load(12);
const result = load(12, this);
assert.ok(
result instanceof TrackedAsyncData,
"it returns a TrackedAsyncData instance"
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/tracked-async-data-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ module("Unit | TrackedAsyncData", function () {
// this fails both at the type-checking level and dynamically at runtime.
class Subclass extends TrackedAsyncData<unknown> {}

assert.throws(() => new Subclass(Promise.resolve("nope")));
assert.throws(() => new Subclass(Promise.resolve("nope"), this));
});

test("is initially PENDING", async function (assert) {
assert.expect(6);
const deferred = defer();

const result = new TrackedAsyncData(deferred.promise);
const result = new TrackedAsyncData(deferred.promise, this);
assert.equal(result.state, "PENDING");
assert.equal(result.isPending, true);
assert.equal(result.isResolved, false);
Expand All @@ -32,7 +32,7 @@ module("Unit | TrackedAsyncData", function () {
assert.expect(6);

const deferred = defer();
const result = new TrackedAsyncData(deferred.promise);
const result = new TrackedAsyncData(deferred.promise, this);

deferred.resolve("foobar");
await settled();
Expand All @@ -49,7 +49,7 @@ module("Unit | TrackedAsyncData", function () {
test("undefined", async function (assert) {
assert.expect(6);

const loadUndefined = new TrackedAsyncData(undefined);
const loadUndefined = new TrackedAsyncData(undefined, this);
await settled();

assert.equal(loadUndefined.state, "RESOLVED");
Expand All @@ -63,7 +63,7 @@ module("Unit | TrackedAsyncData", function () {
test("null", async function (assert) {
assert.expect(6);

const loadNull = new TrackedAsyncData(null);
const loadNull = new TrackedAsyncData(null, this);
await settled();

assert.equal(loadNull.state, "RESOLVED");
Expand All @@ -78,7 +78,7 @@ module("Unit | TrackedAsyncData", function () {
assert.expect(6);

const notAThenableObject = { notAThenable: true };
const loadObject = new TrackedAsyncData(notAThenableObject);
const loadObject = new TrackedAsyncData(notAThenableObject, this);
await settled();

assert.equal(loadObject.state, "RESOLVED");
Expand All @@ -92,7 +92,7 @@ module("Unit | TrackedAsyncData", function () {
test("boolean: true", async function (assert) {
assert.expect(6);

const loadTrue = new TrackedAsyncData(true);
const loadTrue = new TrackedAsyncData(true, this);
await settled();

assert.equal(loadTrue.state, "RESOLVED");
Expand All @@ -106,7 +106,7 @@ module("Unit | TrackedAsyncData", function () {
test("boolean: false", async function (assert) {
assert.expect(6);

const loadFalse = new TrackedAsyncData(false);
const loadFalse = new TrackedAsyncData(false, this);
await settled();

assert.equal(loadFalse.state, "RESOLVED");
Expand All @@ -120,7 +120,7 @@ module("Unit | TrackedAsyncData", function () {
test("number", async function (assert) {
assert.expect(6);

const loadNumber = new TrackedAsyncData(5);
const loadNumber = new TrackedAsyncData(5, this);
await settled();

assert.equal(loadNumber.state, "RESOLVED");
Expand All @@ -134,7 +134,7 @@ module("Unit | TrackedAsyncData", function () {
test("string", async function (assert) {
assert.expect(6);

const loadString = new TrackedAsyncData("js");
const loadString = new TrackedAsyncData("js", this);
await settled();

// loadString
Expand All @@ -152,7 +152,7 @@ module("Unit | TrackedAsyncData", function () {

// This handles the error throw from rendering a rejected promise
const deferred = defer();
const result = new TrackedAsyncData(deferred.promise);
const result = new TrackedAsyncData(deferred.promise, this);

deferred.reject(new Error("foobar"));
await deferred.promise.catch((error) => {
Expand All @@ -174,7 +174,7 @@ module("Unit | TrackedAsyncData", function () {
assert.expect(2);

const deferred = defer();
const result = new TrackedAsyncData(deferred.promise);
const result = new TrackedAsyncData(deferred.promise, this);
assert.equal(result.state, "PENDING");

deferred.resolve();
Expand All @@ -187,7 +187,7 @@ module("Unit | TrackedAsyncData", function () {
assert.expect(3);

const deferred = defer();
const result = new TrackedAsyncData(deferred.promise);
const result = new TrackedAsyncData(deferred.promise, this);
assert.equal(result.state, "PENDING");

deferred.reject(new Error("foobar"));
Expand Down
3 changes: 1 addition & 2 deletions type-tests/load-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import Load, { load } from "ember-async-data/helpers/load";
import { expectTypeOf } from "expect-type";

expectTypeOf(load).toEqualTypeOf<
<T>(data: T | Promise<T>, context?: object) => TrackedAsyncData<T>
<T>(data: T | Promise<T>, context: {}) => TrackedAsyncData<T>
>();

expectTypeOf(load(true)).toEqualTypeOf(new TrackedAsyncData(true));
expectTypeOf(load(true, {})).toEqualTypeOf(new TrackedAsyncData(true, {}));

interface PublicAPIForHelper<T> extends Helper {
Expand Down
22 changes: 11 additions & 11 deletions type-tests/tracked-async-data-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ declare class PublicAPI<T> {
toString(): string;
}

expectTypeOf(TrackedAsyncData).toBeConstructibleWith(12);
expectTypeOf(TrackedAsyncData).toBeConstructibleWith("hello");
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(true);
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(null);
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(undefined);
expectTypeOf(TrackedAsyncData).toBeConstructibleWith({ cool: "story" });
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(["neat"]);
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(Promise.resolve());
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(Promise.resolve(12));
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(Promise.reject());
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(Promise.reject("gah"));
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(12, {});
expectTypeOf(TrackedAsyncData).toBeConstructibleWith("hello", {});
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(true, {});
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(null, {});
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(undefined, {});
expectTypeOf(TrackedAsyncData).toBeConstructibleWith({ cool: "story" }, {});
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(["neat"], {});
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(Promise.resolve(), {});
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(Promise.resolve(12), {});
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(Promise.reject(), {});
expectTypeOf(TrackedAsyncData).toBeConstructibleWith(Promise.reject("gah"), {});

// We use `toMatchTypeOf` here to confirm the union type which makes up
// `TrackedAsyncData` is structurally compatible with the desired public
Expand Down

0 comments on commit 8e67fac

Please sign in to comment.