Skip to content

Commit 4a82bba

Browse files
committed
test: unit tests for promises.ts
1 parent 7304ec3 commit 4a82bba

5 files changed

Lines changed: 18 additions & 6 deletions

File tree

test/arrays.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { chunkArray, zip } from "../lib/arrays.ts";
22

3-
const expect = chai.expect;
4-
53
describe("arrays.ts", () => {
64
describe("chunkArray", () => {
75
it("12-length array with chunk size 4 => 3x4-element array output", () => {

test/map.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { ExtendedMap, extendGlobally, extendMap } from "../lib/map.ts";
22

3-
const expect = chai.expect;
4-
53
describe("map.ts", () => {
64
describe("ExtendedMap", () => {
75
it("basic map functionality", () => {

test/promises.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { wait } from "../lib/promises.ts";
2+
3+
describe("promises.ts", () => {
4+
describe("wait", function () {
5+
this.timeout(1000);
6+
this.slow(500);
7+
8+
it("resolves after the given amount of time", async () => {
9+
const start = performance.now();
10+
await expect(wait(201)).to.eventually.equal(undefined);
11+
const elapsed = performance.now() - start;
12+
expect(elapsed).to.be.greaterThanOrEqual(200);
13+
});
14+
});
15+
});

test/semaphore.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Semaphore } from "../lib/semaphore.ts";
22

3-
const expect = chai.expect;
4-
53
describe("semaphore.ts", () => {
64
// a semaphore class with public acquire/release methods for testing
75
class OpenSemaphore extends Semaphore {

test/support/setup.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import spies from "chai-spies";
55
declare global {
66
// eslint-disable-next-line vars-on-top, no-var
77
var chai: Chai.ChaiStatic;
8+
// eslint-disable-next-line vars-on-top, no-var
9+
var expect: Chai.ExpectStatic;
810
}
911

1012
globalThis.chai = use(chaiAsPromised);
1113
globalThis.chai = chai.use(spies);
14+
globalThis.expect = chai.expect;

0 commit comments

Comments
 (0)