-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HCK-9565: init unit tests automation config (#36)
* HCK-9565: add base unit tests example using nodejs test runner * prettify example tests and fix hooks installation * move running tests to pre-push hook * finalize running tests on pre-push hook
- Loading branch information
1 parent
87d5eb6
commit c8a6dc1
Showing
5 changed files
with
58 additions
and
2 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,11 @@ | ||
const { add, multiply } = require('./math'); | ||
|
||
function calculateSum(a, b) { | ||
return add(a, b); | ||
} | ||
|
||
function calculateProduct(a, b) { | ||
return multiply(a, b); | ||
} | ||
|
||
module.exports = { calculateSum, calculateProduct }; |
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,33 @@ | ||
const { mock, before, describe, it } = require('node:test'); | ||
const assert = require('node:assert'); | ||
|
||
describe('calculator', () => { | ||
let calculator; | ||
let addSpy; | ||
let multiplySpy; | ||
|
||
before(() => { | ||
addSpy = mock.fn(() => 42); | ||
multiplySpy = mock.fn(() => -1); | ||
|
||
mock.module('./math', { | ||
namedExports: { | ||
add: addSpy, | ||
multiply: multiplySpy, | ||
}, | ||
}); | ||
calculator = require('./calculator'); | ||
}); | ||
|
||
it('calculateSum uses mocked add function', () => { | ||
const result = calculator.calculateSum(2, 3); | ||
assert.strictEqual(result, 42); | ||
assert.strictEqual(addSpy.mock.calls.length, 1); | ||
}); | ||
|
||
it('calculateProduct uses mocked multiply function', () => { | ||
const result = calculator.calculateProduct(2, 3); | ||
assert.strictEqual(result, -1); | ||
assert.strictEqual(multiplySpy.mock.calls.length, 1); | ||
}); | ||
}); |
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,9 @@ | ||
function add(a, b) { | ||
return a + b; | ||
} | ||
|
||
function multiply(a, b) { | ||
return a * b; | ||
} | ||
|
||
module.exports = { add, multiply }; |