Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Commit

Permalink
test: add tests for Intermediate
Browse files Browse the repository at this point in the history
  • Loading branch information
priestine committed Mar 24, 2020
1 parent cd0da8b commit 5d92153
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/helpers/intermediate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { IntermediateInterface } from "../interfaces";
import { isIntermediate } from "./is-intermediate";

export class Intermediate<T = {}> implements IntermediateInterface {
public static of<T>(value: T): Intermediate<T> {
return new Intermediate(value);
}

public static isIntermediate(x: unknown): x is IntermediateInterface {
return isIntermediate(x);
return typeof x == "object" && x != null && "intermediate" in x;
}

public intermediate: T;
Expand Down
22 changes: 22 additions & 0 deletions test/intermediate.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Intermediate } from "../src";

describe("Intermediate", (): void => {
it("should return an Intermediate", (): void => {
expect(Intermediate.of(123)).toBeInstanceOf(Intermediate);
});

it("should wrap given value into IntermediateInterface", (): void => {
expect(Intermediate.of(123).intermediate).toEqual(123);
});
});

describe("Intermediate.isIntermediate", (): void => {
it("should return true if argument is intermediate", (): void => {
expect(Intermediate.isIntermediate({ intermediate: 123 })).toEqual(true);
});

it("should return false if provided argument is not intermediate", (): void => {
expect(Intermediate.isIntermediate(123)).toEqual(false);
expect(Intermediate.isIntermediate({ key: 123 })).toEqual(false);
});
});

0 comments on commit 5d92153

Please sign in to comment.