Skip to content

Commit a92de93

Browse files
committed
Convert tests away from CoffeeScript
Also make them stop relying on global setup.
1 parent ce2d4cb commit a92de93

22 files changed

+1473
-1115
lines changed

package-lock.json

Lines changed: 24 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
"lib"
2121
],
2222
"scripts": {
23-
"test": "npm run test-plugin && npm run test-intercompatibility",
24-
"test-plugin": "mocha",
25-
"test-intercompatibility": "mocha test-intercompatibility --opts test-intercompatibility/mocha.opts",
23+
"test": "mocha",
2624
"test-travis": "npm install chai@$CHAI_VERSION && npm test",
2725
"lint": "eslint .",
2826
"cover": "istanbul cover node_modules/mocha/bin/_mocha && opener ./coverage/lcov-report/lib/chai-as-promised.js.html"
@@ -36,7 +34,6 @@
3634
},
3735
"devDependencies": {
3836
"chai": "^4.0.2",
39-
"coffee-script": "1.10.0",
4037
"istanbul": "0.4.5",
4138
"mocha": "^3.4.2"
4239
}

test-intercompatibility/chainable-methods.coffee

Lines changed: 0 additions & 31 deletions
This file was deleted.

test-intercompatibility/mocha.opts

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/assert-eventually.coffee

Lines changed: 0 additions & 98 deletions
This file was deleted.

test/assert-eventually.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
"use strict";
2+
require("./support/setup.js");
3+
const shouldPass = require("./support/common.js").shouldPass;
4+
const shouldFail = require("./support/common.js").shouldFail;
5+
const assert = require("chai").assert;
6+
const expect = require("chai").expect;
7+
8+
describe("Assert interface with eventually extender:", () => {
9+
let promise = null;
10+
11+
describe("Direct tests of fulfilled promises", () => {
12+
it(".eventually.isNull(promise)", done => {
13+
assert.eventually.isNull(Promise.resolve(null)).notify(done);
14+
});
15+
it(".eventually.isFunction(promise)", done => {
16+
assert.eventually.isFunction(Promise.resolve(() => { /* Forever pending */ })).notify(done);
17+
});
18+
it(".eventually.typeOf(promise, 'string')", done => {
19+
assert.eventually.typeOf(Promise.resolve("hello"), "string").notify(done);
20+
});
21+
it(".eventually.include(promiseForString, 'substring')", done => {
22+
assert.eventually.include(Promise.resolve("hello"), "hell").notify(done);
23+
});
24+
it(".eventually.include(promiseForArray, arrayMember)", done => {
25+
assert.eventually.include(Promise.resolve([1, 2, 3]), 1).notify(done);
26+
});
27+
});
28+
29+
describe("On a promise fulfilled with the number 42", () => {
30+
beforeEach(() => {
31+
promise = Promise.resolve(42);
32+
});
33+
34+
describe(".eventually.isNull(promise)", () => {
35+
shouldFail({
36+
op: () => assert.eventually.isNull(promise),
37+
message: "to equal null"
38+
});
39+
});
40+
describe(".eventually.isDefined(promise)", () => {
41+
shouldPass(() => assert.eventually.isDefined(promise));
42+
});
43+
describe(".eventually.ok(promise)", () => {
44+
shouldPass(() => assert.eventually.ok(promise));
45+
});
46+
describe(".eventually.equal(promise, 42)", () => {
47+
shouldPass(() => assert.eventually.equal(promise, 42));
48+
});
49+
describe(".eventually.equal(promise, 52)", () => {
50+
shouldFail({
51+
op: () => assert.eventually.equal(promise, 52),
52+
message: "to equal 52"
53+
});
54+
55+
function shouldFailWithCorrectActual(promiseProducer) {
56+
it("should return a promise rejected with an assertion error that has actual/expected properties " +
57+
"correct", done => {
58+
expect(promiseProducer().then(
59+
() => {
60+
throw new Error("promise fulfilled");
61+
},
62+
e => {
63+
e.actual.should.equal(42);
64+
e.expected.should.equal(52);
65+
}
66+
)).to.be.fulfilled.notify(done);
67+
});
68+
}
69+
70+
describe("assert", () => {
71+
shouldFailWithCorrectActual(() => assert.eventually.equal(promise, 52));
72+
});
73+
describe("expect", () => {
74+
shouldFailWithCorrectActual(() => expect(promise).to.eventually.equal(52));
75+
});
76+
describe("should", () => {
77+
shouldFailWithCorrectActual(() => promise.should.eventually.equal(52));
78+
});
79+
});
80+
81+
describe(".eventually.notEqual(promise, 42)", () => {
82+
shouldFail({
83+
op: () => assert.eventually.notEqual(promise, 42),
84+
message: "to not equal 42"
85+
});
86+
});
87+
describe(".eventually.notEqual(promise, 52)", () => {
88+
shouldPass(() => assert.eventually.notEqual(promise, 52));
89+
});
90+
});
91+
92+
describe("On a promise fulfilled with { foo: 'bar' }", () => {
93+
beforeEach(() => {
94+
promise = Promise.resolve({ foo: "bar" });
95+
});
96+
97+
describe(".eventually.equal(promise, { foo: 'bar' })", () => {
98+
shouldFail({
99+
op: () => assert.eventually.equal(promise, { foo: "bar" }),
100+
message: "to equal { foo: 'bar' }"
101+
});
102+
});
103+
describe(".eventually.deepEqual(promise, { foo: 'bar' })", () => {
104+
shouldPass(() => assert.eventually.deepEqual(promise, { foo: "bar" }));
105+
});
106+
});
107+
108+
describe("Assertion messages", () => {
109+
const message = "He told me enough! He told me you killed him!";
110+
111+
describe("should pass through for .eventually.isNull(promise, message) for fulfilled", () => {
112+
shouldFail({
113+
op: () => assert.eventually.isNull(Promise.resolve(42), message),
114+
message
115+
});
116+
});
117+
118+
describe("should pass through for .eventually.isNull(promise, message) for rejected", () => {
119+
shouldFail({
120+
op: () => assert.eventually.isNull(Promise.reject(), message),
121+
message
122+
});
123+
});
124+
125+
describe("should pass through for .eventually.equal(promise, 52, message) for fulfilled", () => {
126+
shouldFail({
127+
op: () => assert.eventually.equal(Promise.resolve(42), 52, message),
128+
message
129+
});
130+
});
131+
132+
describe("should pass through for .eventually.equal(promise, 52, message) for rejected", () => {
133+
shouldFail({
134+
op: () => assert.eventually.equal(Promise.reject(), 52, message),
135+
message
136+
});
137+
});
138+
});
139+
});

0 commit comments

Comments
 (0)