Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

test: migrate 5 unit test files from unexpected to chai (#5896)

Mostafa Nazarifa06dde40cdb
diff --git a/test/node-unit/cli/mocha-flags.spec.js b/test/node-unit/cli/mocha-flags.spec.js
index 80a38f6e..5218baea 100644
--- a/test/node-unit/cli/mocha-flags.spec.js
+++ b/test/node-unit/cli/mocha-flags.spec.js
@@ -1,5 +1,6 @@
"use strict";
+var { expect } = require("chai");
const {
types,
expectedTypeForFlag,
@@ -10,18 +11,18 @@ describe("mocha-flags", function () {
Object.entries(types).forEach(([dataType, flags]) => {
flags.forEach((flag) => {
it(`returns expected ${flag}'s type as ${dataType}`, function () {
- expect(expectedTypeForFlag(flag), "to equal", dataType);
+ expect(expectedTypeForFlag(flag)).to.equal(dataType);
});
});
});
it("returns undefined for node flags", function () {
- expect(expectedTypeForFlag("--throw-deprecation"), "to equal", undefined);
- expect(expectedTypeForFlag("throw-deprecation"), "to equal", undefined);
+ expect(expectedTypeForFlag("--throw-deprecation")).to.equal(undefined);
+ expect(expectedTypeForFlag("throw-deprecation")).to.equal(undefined);
});
it("returns undefined for unsupported flags", function () {
- expect(expectedTypeForFlag("--foo"), "to equal", undefined);
+ expect(expectedTypeForFlag("--foo")).to.equal(undefined);
});
});
});
diff --git a/test/unit/context.spec.js b/test/unit/context.spec.js
index 819dff8f..4c6f6ec6 100644
--- a/test/unit/context.spec.js
+++ b/test/unit/context.spec.js
@@ -1,5 +1,7 @@
"use strict";
+var { expect } = require("chai");
+
describe("Context", function () {
beforeEach(function () {
this.calls = ["before"];
@@ -11,18 +13,18 @@ describe("Context", function () {
});
it("should work", function () {
- expect(this.calls, "to equal", ["before", "before two"]);
+ expect(this.calls).to.deep.equal(["before", "before two"]);
this.calls.push("test");
});
after(function () {
- expect(this.calls, "to equal", ["before", "before two", "test"]);
+ expect(this.calls).to.deep.equal(["before", "before two", "test"]);
this.calls.push("after two");
});
});
after(function () {
- expect(this.calls, "to equal", [
+ expect(this.calls).to.deep.equal([
"before",
"before two",
"test",
@@ -43,7 +45,7 @@ describe("Context Siblings", function () {
});
it("should work", function () {
- expect(this.hiddenFromSibling, "to equal", "This should be hidden");
+ expect(this.hiddenFromSibling).to.equal("This should be hidden");
});
});
@@ -53,25 +55,21 @@ describe("Context Siblings", function () {
});
it("should not have value set within a sibling describe", function () {
- expect("This should be hidden", "not to equal", this.hiddenFromSibling);
+ expect("This should be hidden").to.not.equal(this.hiddenFromSibling);
this.visibleFromTestSibling = "Visible from test sibling";
});
it("should allow test siblings to modify shared context", function () {
- expect(
- "Visible from test sibling",
- "to equal",
- this.visibleFromTestSibling,
- );
+ expect("Visible from test sibling").to.equal(this.visibleFromTestSibling);
});
it("should have reset this.calls before describe", function () {
- expect(this.calls, "to equal", ["before", "before sibling"]);
+ expect(this.calls).to.deep.equal(["before", "before sibling"]);
});
});
after(function () {
- expect(this.calls, "to equal", ["before", "before sibling"]);
+ expect(this.calls).to.deep.equal(["before", "before sibling"]);
});
});
@@ -80,19 +78,19 @@ describe("methods", function () {
it("should return the timeout", function () {
// set this explicitly because browser and node use diff settings
this.timeout(1000);
- expect(this.timeout(), "to be", 1000);
+ expect(this.timeout()).to.equal(1000);
});
});
describe("slow()", function () {
it("should return the slow", function () {
- expect(this.slow(), "to be", 75);
+ expect(this.slow()).to.equal(75);
});
});
describe("retries", function () {
it("should return the number of retries", function () {
- expect(this.retries(), "to be", -1);
+ expect(this.retries()).to.equal(-1);
});
});
});
diff --git a/test/unit/grep.spec.js b/test/unit/grep.spec.js
index c170b0a2..a84f149f 100644
--- a/test/unit/grep.spec.js
+++ b/test/unit/grep.spec.js
@@ -1,24 +1,25 @@
"use strict";
+var { expect } = require("chai");
var Mocha = require("../../lib/mocha");
describe("Mocha", function () {
describe('"grep" option', function () {
it("should add a RegExp to the mocha.options object", function () {
var mocha = new Mocha({ grep: /foo.*/ });
- expect(mocha.options.grep, "to equal", /foo.*/);
+ expect(mocha.options.grep).to.deep.equal(/foo.*/);
});
it("should convert string to a RegExp", function () {
var mocha = new Mocha({ grep: "foo.*" });
- expect(mocha.options.grep, "to equal", /foo.*/);
+ expect(mocha.options.grep).to.deep.equal(/foo.*/);
});
});
describe('"fgrep" option', function () {
it("should escape and convert string to a RegExp", function () {
var mocha = new Mocha({ fgrep: "foo.*" });
- expect(mocha.options.grep, "to equal", /foo\.\*/);
+ expect(mocha.options.grep).to.deep.equal(/foo\.\*/);
});
});
@@ -27,7 +28,7 @@ describe("Mocha", function () {
function testGrep(mocha) {
return function testGrep(grep, expected) {
mocha.grep(grep);
- expect(String(mocha.options.grep), "to be", expected);
+ expect(String(mocha.options.grep)).to.equal(expected);
};
}
@@ -54,14 +55,14 @@ describe("Mocha", function () {
it("should return its parent Mocha object for chainability", function () {
var mocha = new Mocha();
- expect(mocha.grep(), "to be", mocha);
+ expect(mocha.grep()).to.equal(mocha);
});
});
describe('"invert" option', function () {
it("should add a Boolean to the mocha.options object", function () {
var mocha = new Mocha({ invert: true });
- expect(mocha.options.invert, "to be", true);
+ expect(mocha.options.invert).to.equal(true);
});
});
});
diff --git a/test/unit/parse-query.spec.js b/test/unit/parse-query.spec.js
index 8a83d410..0c7cdd02 100644
--- a/test/unit/parse-query.spec.js
+++ b/test/unit/parse-query.spec.js
@@ -1,16 +1,17 @@
"use strict";
-var parseQuery = require("../../lib/browser/parse-query.mjs").parseQuery;
+var { expect } = require("chai");
+var { parseQuery } = require("../../lib/browser/parse-query.mjs");
describe("parseQuery()", function () {
it("should get queryString and return key-value object", function () {
- expect(parseQuery("?foo=1&bar=2&baz=3"), "to equal", {
+ expect(parseQuery("?foo=1&bar=2&baz=3")).to.deep.equal({
foo: "1",
bar: "2",
baz: "3",
});
- expect(parseQuery("?r1=^@(?!.*\\)$)&r2=m{2}&r3=^co.*"), "to equal", {
+ expect(parseQuery("?r1=^@(?!.*\\)$)&r2=m{2}&r3=^co.*")).to.deep.equal({
r1: "^@(?!.*\\)$)",
r2: "m{2}",
r3: "^co.*",
@@ -18,6 +19,6 @@ describe("parseQuery()", function () {
});
it('should parse "+" as a space', function () {
- expect(parseQuery("?grep=foo+bar"), "to equal", { grep: "foo bar" });
+ expect(parseQuery("?grep=foo+bar")).to.deep.equal({ grep: "foo bar" });
});
});
diff --git a/test/unit/root.spec.js b/test/unit/root.spec.js
index c32effec..4f481ba1 100644
--- a/test/unit/root.spec.js
+++ b/test/unit/root.spec.js
@@ -1,5 +1,6 @@
"use strict";
+var { expect } = require("chai");
var calls = [];
before(function () {
@@ -8,6 +9,6 @@ before(function () {
describe("root", function () {
it("should be a valid suite", function () {
- expect(calls, "to equal", ["before"]);
+ expect(calls).to.deep.equal(["before"]);
});
});