|
| 1 | +/** |
| 2 | + * @overview Contains unit tests for the functionality to read a file system |
| 3 | + * link. |
| 4 | + * @license MIT |
| 5 | + */ |
| 6 | + |
| 7 | +import { testProp } from "@fast-check/ava"; |
| 8 | +import test from "ava"; |
| 9 | +import * as fc from "fast-check"; |
| 10 | +import * as sinon from "sinon"; |
| 11 | + |
| 12 | +import { readlinkSync } from "../../../src/internal/fs.js"; |
| 13 | + |
| 14 | +test.before((t) => { |
| 15 | + const readlinkSync = sinon.mock(); |
| 16 | + |
| 17 | + t.context = { |
| 18 | + deps: { readlinkSync }, |
| 19 | + }; |
| 20 | +}); |
| 21 | + |
| 22 | +testProp("return value", [fc.string(), fc.string()], (t, path, returnValue) => { |
| 23 | + t.context.deps.readlinkSync.resetHistory(); |
| 24 | + t.context.deps.readlinkSync.returns(returnValue); |
| 25 | + |
| 26 | + const result = readlinkSync(path, t.context.deps); |
| 27 | + t.is(result, returnValue); |
| 28 | +}); |
| 29 | + |
| 30 | +testProp( |
| 31 | + "error", |
| 32 | + [fc.string(), fc.string().map((message) => new Error(message))], |
| 33 | + (t, path, error) => { |
| 34 | + t.context.deps.readlinkSync.resetHistory(); |
| 35 | + t.context.deps.readlinkSync.throws(error); |
| 36 | + |
| 37 | + t.throws(() => readlinkSync(path, t.context.deps), { is: error }); |
| 38 | + }, |
| 39 | +); |
| 40 | + |
| 41 | +testProp("fs usage", [fc.string(), fc.string()], (t, path, returnValue) => { |
| 42 | + t.context.deps.readlinkSync.resetHistory(); |
| 43 | + t.context.deps.readlinkSync.returns(returnValue); |
| 44 | + |
| 45 | + readlinkSync(path, t.context.deps); |
| 46 | + t.is(t.context.deps.readlinkSync.callCount, 1); |
| 47 | + t.true(t.context.deps.readlinkSync.calledWithExactly(path)); |
| 48 | +}); |
0 commit comments