Skip to content

Commit

Permalink
Convert tests away from CoffeeScript
Browse files Browse the repository at this point in the history
Also make them stop relying on global setup.
  • Loading branch information
domenic committed Jun 11, 2017
1 parent ce2d4cb commit a92de93
Show file tree
Hide file tree
Showing 22 changed files with 1,473 additions and 1,115 deletions.
42 changes: 24 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
"lib"
],
"scripts": {
"test": "npm run test-plugin && npm run test-intercompatibility",
"test-plugin": "mocha",
"test-intercompatibility": "mocha test-intercompatibility --opts test-intercompatibility/mocha.opts",
"test": "mocha",
"test-travis": "npm install chai@$CHAI_VERSION && npm test",
"lint": "eslint .",
"cover": "istanbul cover node_modules/mocha/bin/_mocha && opener ./coverage/lcov-report/lib/chai-as-promised.js.html"
Expand All @@ -36,7 +34,6 @@
},
"devDependencies": {
"chai": "^4.0.2",
"coffee-script": "1.10.0",
"istanbul": "0.4.5",
"mocha": "^3.4.2"
}
Expand Down
31 changes: 0 additions & 31 deletions test-intercompatibility/chainable-methods.coffee

This file was deleted.

2 changes: 0 additions & 2 deletions test-intercompatibility/mocha.opts

This file was deleted.

98 changes: 0 additions & 98 deletions test/assert-eventually.coffee

This file was deleted.

139 changes: 139 additions & 0 deletions test/assert-eventually.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
"use strict";
require("./support/setup.js");
const shouldPass = require("./support/common.js").shouldPass;
const shouldFail = require("./support/common.js").shouldFail;
const assert = require("chai").assert;
const expect = require("chai").expect;

describe("Assert interface with eventually extender:", () => {
let promise = null;

describe("Direct tests of fulfilled promises", () => {
it(".eventually.isNull(promise)", done => {
assert.eventually.isNull(Promise.resolve(null)).notify(done);
});
it(".eventually.isFunction(promise)", done => {
assert.eventually.isFunction(Promise.resolve(() => { /* Forever pending */ })).notify(done);
});
it(".eventually.typeOf(promise, 'string')", done => {
assert.eventually.typeOf(Promise.resolve("hello"), "string").notify(done);
});
it(".eventually.include(promiseForString, 'substring')", done => {
assert.eventually.include(Promise.resolve("hello"), "hell").notify(done);
});
it(".eventually.include(promiseForArray, arrayMember)", done => {
assert.eventually.include(Promise.resolve([1, 2, 3]), 1).notify(done);
});
});

describe("On a promise fulfilled with the number 42", () => {
beforeEach(() => {
promise = Promise.resolve(42);
});

describe(".eventually.isNull(promise)", () => {
shouldFail({
op: () => assert.eventually.isNull(promise),
message: "to equal null"
});
});
describe(".eventually.isDefined(promise)", () => {
shouldPass(() => assert.eventually.isDefined(promise));
});
describe(".eventually.ok(promise)", () => {
shouldPass(() => assert.eventually.ok(promise));
});
describe(".eventually.equal(promise, 42)", () => {
shouldPass(() => assert.eventually.equal(promise, 42));
});
describe(".eventually.equal(promise, 52)", () => {
shouldFail({
op: () => assert.eventually.equal(promise, 52),
message: "to equal 52"
});

function shouldFailWithCorrectActual(promiseProducer) {
it("should return a promise rejected with an assertion error that has actual/expected properties " +
"correct", done => {
expect(promiseProducer().then(
() => {
throw new Error("promise fulfilled");
},
e => {
e.actual.should.equal(42);
e.expected.should.equal(52);
}
)).to.be.fulfilled.notify(done);
});
}

describe("assert", () => {
shouldFailWithCorrectActual(() => assert.eventually.equal(promise, 52));
});
describe("expect", () => {
shouldFailWithCorrectActual(() => expect(promise).to.eventually.equal(52));
});
describe("should", () => {
shouldFailWithCorrectActual(() => promise.should.eventually.equal(52));
});
});

describe(".eventually.notEqual(promise, 42)", () => {
shouldFail({
op: () => assert.eventually.notEqual(promise, 42),
message: "to not equal 42"
});
});
describe(".eventually.notEqual(promise, 52)", () => {
shouldPass(() => assert.eventually.notEqual(promise, 52));
});
});

describe("On a promise fulfilled with { foo: 'bar' }", () => {
beforeEach(() => {
promise = Promise.resolve({ foo: "bar" });
});

describe(".eventually.equal(promise, { foo: 'bar' })", () => {
shouldFail({
op: () => assert.eventually.equal(promise, { foo: "bar" }),
message: "to equal { foo: 'bar' }"
});
});
describe(".eventually.deepEqual(promise, { foo: 'bar' })", () => {
shouldPass(() => assert.eventually.deepEqual(promise, { foo: "bar" }));
});
});

describe("Assertion messages", () => {
const message = "He told me enough! He told me you killed him!";

describe("should pass through for .eventually.isNull(promise, message) for fulfilled", () => {
shouldFail({
op: () => assert.eventually.isNull(Promise.resolve(42), message),
message
});
});

describe("should pass through for .eventually.isNull(promise, message) for rejected", () => {
shouldFail({
op: () => assert.eventually.isNull(Promise.reject(), message),
message
});
});

describe("should pass through for .eventually.equal(promise, 52, message) for fulfilled", () => {
shouldFail({
op: () => assert.eventually.equal(Promise.resolve(42), 52, message),
message
});
});

describe("should pass through for .eventually.equal(promise, 52, message) for rejected", () => {
shouldFail({
op: () => assert.eventually.equal(Promise.reject(), 52, message),
message
});
});
});
});
Loading

0 comments on commit a92de93

Please sign in to comment.