-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58a8eb4
commit 22aa05c
Showing
3 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('node:assert'); | ||
const { describe, it } = require('node:test'); | ||
|
||
const testCases = { | ||
greaterThan: [ | ||
{ actual: 5, expected: 3, shouldPass: true }, | ||
{ actual: 3, expected: 3, shouldPass: false }, | ||
{ actual: 2, expected: 3, shouldPass: false }, | ||
], | ||
atLeast: [ | ||
{ actual: 5, expected: 3, shouldPass: true }, | ||
{ actual: 3, expected: 3, shouldPass: true }, | ||
{ actual: 2, expected: 3, shouldPass: false }, | ||
], | ||
lessThan: [ | ||
{ actual: 2, expected: 3, shouldPass: true }, | ||
{ actual: 3, expected: 3, shouldPass: false }, | ||
{ actual: 4, expected: 3, shouldPass: false }, | ||
], | ||
atMost: [ | ||
{ actual: 2, expected: 3, shouldPass: true }, | ||
{ actual: 3, expected: 3, shouldPass: true }, | ||
{ actual: 4, expected: 3, shouldPass: false }, | ||
] | ||
}; | ||
|
||
const comparison = { | ||
greaterThan: 'greater than', | ||
atLeast: 'greater than or equal to', | ||
lessThan: 'less than', | ||
atMost: 'less than or equal to' | ||
}; | ||
|
||
const methods = Object.keys(testCases); | ||
|
||
for (const method of methods) { | ||
describe(`assert.${method}`, () => { | ||
for (const { actual, expected, shouldPass } of testCases[method]) { | ||
it(`should ${shouldPass ? 'pass' : 'fail'} with (${actual}, ${expected})`, () => { | ||
assert[shouldPass ? 'doesNotThrow' : 'throws']( | ||
() => assert[method](actual, expected), | ||
new RegExp(`Expected ${actual} to be ${comparison[method]} ${expected}`) | ||
); | ||
}); | ||
} | ||
}); | ||
} |