Skip to content

Commit 0037ce9

Browse files
not-an-aardvarkkaicataldo
authored andcommitted
Chore: avoid loose equality assertions (#9415)
* Chore: avoid loose equality assertions This updates the `no-restricted-syntax` configuration to disallow `assert.equal` and `assert.notEqual` in favor of `assert.strictEqual` and `assert.notStrictEqual`. It also fixes a few places where the tests were relying on a loose equality check (e.g. comparing a single-element array to a string). * Use assert.deepStrictEqual instead of assert.deepEqual * Revert accidental fixture changes
1 parent 188d984 commit 0037ce9

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

test.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("formatter:codeframe", () => {
6363
it("should return nothing", () => {
6464
const result = formatter(code);
6565

66-
assert.equal(result, "");
66+
assert.strictEqual(result, "");
6767
});
6868
});
6969

@@ -87,7 +87,7 @@ describe("formatter:codeframe", () => {
8787
it("should return a string in the correct format for warnings", () => {
8888
const result = formatter(code);
8989

90-
assert.equal(stripAnsi(result), [
90+
assert.strictEqual(stripAnsi(result), [
9191
`warning: Unexpected foo (foo) at ${path.join("lib", "foo.js")}:1:5:`,
9292
"> 1 | var foo = 1;",
9393
" | ^",
@@ -104,8 +104,8 @@ describe("formatter:codeframe", () => {
104104

105105
formatter(code);
106106

107-
assert.equal(chalkStub.yellow.bold.callCount, 1);
108-
assert.equal(chalkStub.red.bold.callCount, 0);
107+
assert.strictEqual(chalkStub.yellow.bold.callCount, 1);
108+
assert.strictEqual(chalkStub.red.bold.callCount, 0);
109109
});
110110

111111
describe("when the warning is fixable", () => {
@@ -116,7 +116,7 @@ describe("formatter:codeframe", () => {
116116
it("should return a string in the correct format", () => {
117117
const result = formatter(code);
118118

119-
assert.equal(stripAnsi(result), [
119+
assert.strictEqual(stripAnsi(result), [
120120
`warning: Unexpected foo (foo) at ${path.join("lib", "foo.js")}:1:5:`,
121121
"> 1 | var foo = 1;",
122122
" | ^",
@@ -148,7 +148,7 @@ describe("formatter:codeframe", () => {
148148
it("should return a string in the correct format for errors", () => {
149149
const result = formatter(code);
150150

151-
assert.equal(stripAnsi(result), [
151+
assert.strictEqual(stripAnsi(result), [
152152
`error: Unexpected foo (foo) at ${path.join("lib", "foo.js")}:1:5:`,
153153
"> 1 | var foo = 1;",
154154
" | ^",
@@ -165,8 +165,8 @@ describe("formatter:codeframe", () => {
165165

166166
formatter(code);
167167

168-
assert.equal(chalkStub.yellow.bold.callCount, 0);
169-
assert.equal(chalkStub.red.bold.callCount, 1);
168+
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
169+
assert.strictEqual(chalkStub.red.bold.callCount, 1);
170170
});
171171
});
172172

@@ -186,7 +186,7 @@ describe("formatter:codeframe", () => {
186186
it("should return a string in the correct format (retaining the ' .')", () => {
187187
const result = formatter(code);
188188

189-
assert.equal(stripAnsi(result), "error: Unexpected . (foo) at foo.js\n\n\n1 error found.");
189+
assert.strictEqual(stripAnsi(result), "error: Unexpected . (foo) at foo.js\n\n\n1 error found.");
190190
});
191191
});
192192

@@ -214,7 +214,7 @@ describe("formatter:codeframe", () => {
214214
it("should return a string with multiple entries", () => {
215215
const result = formatter(code);
216216

217-
assert.equal(stripAnsi(result), [
217+
assert.strictEqual(stripAnsi(result), [
218218
"error: Missing semicolon (semi) at foo.js:1:14:",
219219
"> 1 | const foo = 1",
220220
" | ^",
@@ -238,8 +238,8 @@ describe("formatter:codeframe", () => {
238238

239239
formatter(code);
240240

241-
assert.equal(chalkStub.yellow.bold.callCount, 0);
242-
assert.equal(chalkStub.red.bold.callCount, 1);
241+
assert.strictEqual(chalkStub.yellow.bold.callCount, 0);
242+
assert.strictEqual(chalkStub.red.bold.callCount, 1);
243243
});
244244
});
245245

@@ -262,7 +262,7 @@ describe("formatter:codeframe", () => {
262262
it("should return a string with code preview pointing to the correct location after fixes", () => {
263263
const result = formatter(code);
264264

265-
assert.equal(stripAnsi(result), [
265+
assert.strictEqual(stripAnsi(result), [
266266
"error: 'foo' is assigned a value but never used (no-unused-vars) at foo.js:4:11:",
267267
" 2 | ",
268268
" 3 | // a comment",
@@ -307,7 +307,7 @@ describe("formatter:codeframe", () => {
307307
it("should return a string with multiple entries", () => {
308308
const result = formatter(code);
309309

310-
assert.equal(stripAnsi(result), [
310+
assert.strictEqual(stripAnsi(result), [
311311
"error: Missing semicolon (semi) at foo.js:1:14:",
312312
"> 1 | const foo = 1",
313313
" | ^",
@@ -343,7 +343,7 @@ describe("formatter:codeframe", () => {
343343
it("should return a string in the correct format", () => {
344344
const result = formatter(code);
345345

346-
assert.equal(stripAnsi(result), [
346+
assert.strictEqual(stripAnsi(result), [
347347
"error: Parsing error: Unexpected token { at foo.js:1:2:",
348348
"> 1 | e{}",
349349
" | ^",
@@ -368,7 +368,7 @@ describe("formatter:codeframe", () => {
368368
it("should return a string without code preview (codeframe)", () => {
369369
const result = formatter(code);
370370

371-
assert.equal(stripAnsi(result), "error: Couldn't find foo.js at foo.js\n\n\n1 error found.");
371+
assert.strictEqual(stripAnsi(result), "error: Couldn't find foo.js at foo.js\n\n\n1 error found.");
372372
});
373373
});
374374

@@ -388,13 +388,13 @@ describe("formatter:codeframe", () => {
388388
it("should return a string without code preview (codeframe)", () => {
389389
const result = formatter(code);
390390

391-
assert.equal(stripAnsi(result), "error: Unexpected foo (foo) at foo.js\n\n\n1 error found.");
391+
assert.strictEqual(stripAnsi(result), "error: Unexpected foo (foo) at foo.js\n\n\n1 error found.");
392392
});
393393

394394
it("should output filepath but without 'line:column' appended", () => {
395395
const result = formatter(code);
396396

397-
assert.equal(stripAnsi(result), "error: Unexpected foo (foo) at foo.js\n\n\n1 error found.");
397+
assert.strictEqual(stripAnsi(result), "error: Unexpected foo (foo) at foo.js\n\n\n1 error found.");
398398
});
399399
});
400400

0 commit comments

Comments
 (0)