Created
June 10, 2023 18:01
-
-
Save luizcalaca/bcf0630cd8959a27df10d5bc165b5a17 to your computer and use it in GitHub Desktop.
Tests in Node.js 20 - built-in test runner
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
import { test, mock } from 'node:test'; | |
import assert from 'node:assert'; | |
import fs from 'node:fs'; | |
test('first test', (t) => { | |
assert.strictEqual(8, 8); | |
}); | |
test('second test', (t) => { | |
assert.strictEqual(9, 9); | |
}); | |
mock.method(fs, 'readFile', async () => 'Lorem ipsum'); | |
test('third test', async (t) => { | |
assert.strictEqual( await fs.readFile('anyfile'), 'Lorem ipsum' ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment