-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove mockedFunction for Node.js test runner mock method (#…
…201)
- Loading branch information
1 parent
8d8abe0
commit 0f88b48
Showing
4 changed files
with
73 additions
and
89 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,56 @@ | ||
// Import Node.js dependencies | ||
import { test } from "node:test"; | ||
import assert from "node:assert"; | ||
|
||
// Import Internal Dependencies | ||
import { getSastAnalysis, parseScript } from "../utils/index.js"; | ||
import isArrayExpression from "../../src/probes/isArrayExpression.js"; | ||
|
||
test("it should trigger analyzeLiteral method one time", (t) => { | ||
const str = "['foo']"; | ||
|
||
const ast = parseScript(str); | ||
const sastAnalysis = getSastAnalysis(str, isArrayExpression); | ||
|
||
t.mock.method(sastAnalysis.analysis, "analyzeLiteral"); | ||
sastAnalysis.execute(ast.body); | ||
|
||
assert.strictEqual(sastAnalysis.warnings().length, 0); | ||
|
||
const calls = sastAnalysis.analysis.analyzeLiteral.mock.calls; | ||
assert.strictEqual(calls.length, 1); | ||
|
||
const literalNode = calls[0].arguments[0]; | ||
assert.strictEqual(literalNode.value, "foo"); | ||
}); | ||
|
||
test("it should trigger analyzeLiteral method two times (ignoring the holey between)", (t) => { | ||
const str = "[5, ,10]"; | ||
|
||
const ast = parseScript(str); | ||
const sastAnalysis = getSastAnalysis(str, isArrayExpression); | ||
|
||
t.mock.method(sastAnalysis.analysis, "analyzeLiteral"); | ||
sastAnalysis.execute(ast.body); | ||
|
||
const calls = sastAnalysis.analysis.analyzeLiteral.mock.calls; | ||
assert.strictEqual(calls.length, 2); | ||
assert.strictEqual(calls[0].arguments[0].value, 5); | ||
assert.strictEqual(calls[1].arguments[0].value, 10); | ||
}); | ||
|
||
test("it should trigger analyzeLiteral one time (ignoring non-literal Node)", (t) => { | ||
const str = "[5, () => void 0]"; | ||
|
||
const ast = parseScript(str); | ||
const sastAnalysis = getSastAnalysis(str, isArrayExpression); | ||
|
||
t.mock.method(sastAnalysis.analysis, "analyzeLiteral"); | ||
sastAnalysis.execute(ast.body); | ||
|
||
const calls = sastAnalysis.analysis.analyzeLiteral.mock.calls; | ||
assert.strictEqual(calls.length, 1); | ||
|
||
const literalNode = calls[0].arguments[0]; | ||
assert.strictEqual(literalNode.value, 5); | ||
}); |
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