Skip to content

Instantly share code, notes, and snippets.

@luizcalaca
Created June 10, 2023 18:01
Show Gist options
  • Save luizcalaca/bcf0630cd8959a27df10d5bc165b5a17 to your computer and use it in GitHub Desktop.
Save luizcalaca/bcf0630cd8959a27df10d5bc165b5a17 to your computer and use it in GitHub Desktop.
Tests in Node.js 20 - built-in test runner
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