os-mock
v1.1.0
Published
Jest OS Mock extension
Maintainers
Readme
OsMock
OsMock is a preset for mocking operating system information using Jest in Node.js projects.
📦 Installation
First, install Jest (if you haven’t already):
npm install jest --save-devThen, install OsMock:
npm install os-mock --save-dev⚙️ Configuration
Add to your jest config file (e.g., jest.config.js) the following line:
{
preset: "os-mock",
}Optional
Add the following configuration to your Jest config file:
{
// Your previews config...
globals: {
osMock: {
platform: "darwin",
hostname: "macbook-pro",
cpuModel: "Apple M1",
totalmem: 16 * 1024 * 1024 * 1024,
freemem: 8 * 1024 * 1024 * 1024,
}
}
}These values will be used to mock the information provided by Node.js's os module during test execution.
💡 Example Usage
const os = require("os");
test("should return the mocked hostname", () => {
expect(os.hostname()).toBe("macbook-pro");
});