Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javierbrea committed Nov 1, 2019
1 parent 6ad2b18 commit e0d58bd
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions test/link.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const path = require("path");

const sinon = require("sinon");
const fsExtra = require("fs-extra");

const paths = require("../src/utils/paths");
const packages = require("../src/utils/packages");
const link = require("../src/link");
const inquire = require("../src/inquire");
Expand All @@ -11,15 +11,11 @@ const npm = require("../src/npm");
describe("link", () => {
let sandbox;
let writeStub;
let workingPathStub;
let chooseStub;

beforeEach(() => {
sandbox = sinon.createSandbox();
writeStub = sandbox.stub(packages, "writePackageJson").resolves();
workingPathStub = sandbox
.stub(paths, "getWorkingPath")
.resolves(path.resolve(__dirname, "fixtures"));
chooseStub = sandbox.stub(inquire, "choose").callsFake(allPackages => {
return Promise.resolve({
toLink: allPackages,
Expand All @@ -35,8 +31,16 @@ describe("link", () => {
});

describe("all method", () => {
it("should reject if no package.json file is found in current folder", async () => {
sandbox.stub(fsExtra, "readJson").rejects(new Error());
sandbox.stub(process, "cwd").returns(path.resolve(__dirname, "fixtures", "foo-package-1"));
expect.assertions(1);
await link.all().catch(err => {
expect(err.message).toEqual(expect.stringContaining("Unable to read"));
});
});

it("should link all locally found dependencies in current package", async () => {
workingPathStub.restore();
sandbox.stub(process, "cwd").returns(path.resolve(__dirname, "fixtures", "foo-package-1"));
expect.assertions(2);
await link.all();
Expand All @@ -57,7 +61,6 @@ describe("link", () => {
});

it("should link all locally found dependencies in current package", async () => {
workingPathStub.restore();
sandbox.stub(process, "cwd").returns(path.resolve(__dirname, "fixtures", "foo-only-dev"));
expect.assertions(2);
await link.all();
Expand All @@ -76,7 +79,6 @@ describe("link", () => {
});

it("should link all locally found devDependencies in current package", async () => {
workingPathStub.restore();
sandbox.stub(process, "cwd").returns(path.resolve(__dirname, "fixtures", "foo-only-deps"));
expect.assertions(2);
await link.all();
Expand All @@ -97,7 +99,6 @@ describe("link", () => {

describe("select method", () => {
it("should modify selected dependencies in current package", async () => {
workingPathStub.restore();
sandbox.stub(process, "cwd").returns(path.resolve(__dirname, "fixtures", "foo-package-1"));
expect.assertions(2);
chooseStub.callsFake(() => {
Expand Down Expand Up @@ -147,7 +148,6 @@ describe("link", () => {
});

it("should show checked currently linked packages", async () => {
workingPathStub.restore();
sandbox
.stub(process, "cwd")
.returns(path.resolve(__dirname, "linked-fixtures", "foo-linked-package"));
Expand Down

0 comments on commit e0d58bd

Please sign in to comment.