Skip to content

Commit

Permalink
test: use nodejs api for mocks
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Gorez <[email protected]>
  • Loading branch information
tony-go committed May 15, 2024
1 parent 481e631 commit 6be439d
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions test/AstAnalyser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ describe("AstAnalyser", (t) => {

describe("intialize", () => {
const analyser = new AstAnalyser();

it("should throw if initialize is not a function", () => {
assert.throws(() => {
analyser.analyse("const foo = 'bar';", {
Expand All @@ -185,29 +186,24 @@ describe("AstAnalyser", (t) => {
});
});

it("should call the initialize function", () => {
let hasBeenCalled = false;
const initialize = () => {
assert.strictEqual(hasBeenCalled, false);
hasBeenCalled = true;
};
it("should call the initialize function", (t) => {
const initialize = t.mock.fn();

analyser.analyse("const foo = 'bar';", {
initialize
});
assert.strictEqual(hasBeenCalled, true);

assert.strictEqual(initialize.mock.callCount(), 1);
});

it("should pass the source file as first argument", () => {
let hasBeenCalled = false;
const initialize = (source) => {
assert.strictEqual(source instanceof SourceFile, true);
};
it("should pass the source file as first argument", (t) => {
const initialize = t.mock.fn();

analyser.analyse("const foo = 'bar';", {
initialize
});
assert.strictEqual(hasBeenCalled, true);

assert.strictEqual(initialize.mock.calls[0].arguments[0] instanceof SourceFile, true);
});
});

Expand All @@ -222,28 +218,23 @@ describe("AstAnalyser", (t) => {
});

it("should call the finalize function", () => {
let hasBeenCalled = false;
const finalize = () => {
assert.strictEqual(hasBeenCalled, false);
hasBeenCalled = true;
};
const finalize = t.mock.fn();

analyser.analyse("const foo = 'bar';", {
finalize
});
assert.strictEqual(hasBeenCalled, true);

assert.strictEqual(finalize.mock.callCount(), 1);
});

it("should pass the source file as first argument", () => {
let hasBeenCalled = false;
const finalize = (source) => {
assert.strictEqual(source instanceof SourceFile, true);
};
const finalize = t.mock.fn();

analyser.analyse("const foo = 'bar';", {
finalize
});
assert.strictEqual(hasBeenCalled, true);

assert.strictEqual(finalize.mock.calls[0].arguments[0] instanceof SourceFile, true);
});
});
});
Expand Down

0 comments on commit 6be439d

Please sign in to comment.