How to use the proxyquire.load function in proxyquire

To help you get started, we’ve selected a few proxyquire examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypedProject / ts-express-decorators / test / units / mvc / decorators / method / authenticated.spec.ts View on Github external
import * as Proxyquire from "proxyquire";
import {Store} from "@tsed/core";
import {descriptorOf} from "@tsed/core";
import {AuthenticatedMiddleware} from "../../../../../packages/common/src/mvc/components/AuthenticatedMiddleware";
import {expect} from "chai";
import * as Sinon from "sinon";

const middleware: any = Sinon.stub();
// tslint:disable-next-line: variable-name
const UseBefore: any = Sinon.stub().returns(middleware);

const {Authenticated} = Proxyquire.load("../../../../../packages/common/src/mvc/decorators/method/authenticated", {
  "./useBefore": {UseBefore}
});

class Test {
  test() {}
}

describe("Authenticated", () => {
  before(() => {
    this.descriptor = {};
    this.options = {options: "options"};

    Authenticated(this.options)(Test, "test", descriptorOf(Test, "test"));
    this.store = Store.fromMethod(Test, "test");
  });
github TypedProject / ts-express-decorators / test / units / mvc / decorators / method / route.spec.ts View on Github external
import {assert} from "chai";
import * as Sinon from "sinon";
import * as Proxyquire from "proxyquire";

const middleware: any = Sinon.stub();
// tslint:disable-next-line: variable-name
const Use: any = Sinon.stub().returns(middleware);

const {All, Get, Post, Put, Delete, Head, Patch} = Proxyquire.load("../../../../../packages/common/src/mvc/decorators/method/route", {
  "./use": {Use}
});

describe("Route decorators", () => {
  describe("All", () => {
    before(() => {
      this.options = ["/", () => {}];
      All(...this.options);
    });

    after(() => {
      delete this.descriptor;
      delete this.options;
    });

    it("should create middleware", () => {
github TypedProject / ts-express-decorators / test / units / mvc / decorators / method / responseView.spec.ts View on Github external
import * as Proxyquire from "proxyquire";
import {Store} from "@tsed/core";
import {ResponseViewMiddleware} from "../../../../../packages/common/src/mvc/components/ResponseViewMiddleware";
import {expect} from "chai";
import * as Sinon from "sinon";

const middleware: any = Sinon.stub();
// tslint:disable-next-line: variable-name
const UseAfter: any = Sinon.stub().returns(middleware);
const {ResponseView} = Proxyquire.load("../../../../../packages/common/src/mvc/decorators/method/responseView", {
  "./useAfter": {UseAfter}
});

class Test {}

describe("ResponseView", () => {
  before(() => {
    this.descriptor = {};
    this.options = ["page", {}];
    ResponseView(...this.options)(Test, "test", this.descriptor);
    this.store = Store.from(Test, "test", this.descriptor);
  });

  after(() => {
    delete this.descriptor;
    delete this.options;
github TypedProject / ts-express-decorators / test / units / mvc / decorators / method / location.spec.ts View on Github external
import {assert, expect} from "chai";
import * as Sinon from "sinon";
import * as Proxyquire from "proxyquire";
import {FakeResponse} from "../../../../helper/FakeResponse";

const middleware: any = Sinon.stub();
// tslint:disable-next-line: variable-name
const UseAfter: any = Sinon.stub().returns(middleware);

const {Location} = Proxyquire.load("../../../../../packages/common/src/mvc/decorators/method/location", {
  "./useAfter": {UseAfter}
});

class Test {}

describe("Location", () => {
  before(() => {
    this.descriptor = {};
    this.options = "test";
    Location(this.options)(Test, "test", this.descriptor);
    this.middleware = UseAfter.args[0][0];
  });

  after(() => {
    delete this.descriptor;
    delete this.options;
github TypedProject / ts-express-decorators / test / units / mvc / decorators / method / header.spec.ts View on Github external
import * as Proxyquire from "proxyquire";
import * as Sinon from "sinon";
import {Store} from "@tsed/core";
import {FakeRequest} from "../../../../helper/FakeRequest";
import {FakeResponse} from "../../../../helper/FakeResponse";
import {expect} from "chai";

let middleware: any;
// tslint:disable-next-line: variable-name
const UseAfterStub: any = (_middleware_: any) => {
  middleware = _middleware_;

  return () => {};
};

const Header = Proxyquire.load("../../../../../packages/common/src/mvc/decorators/method/header", {
  "./useAfter": {UseAfter: UseAfterStub}
}).Header;

class Test {}

describe("Header", () => {
  describe("when is used as method decorator", () => {
    before(() => {
      this.request = new FakeRequest();
      this.response = new FakeResponse();
      Sinon.stub(this.response, "set").returns(this.response);
      this.nextSpy = Sinon.spy();
    });

    after(() => {
      delete this.request;
github TypedProject / ts-express-decorators / test / units / mvc / decorators / params / request.spec.ts View on Github external
import {assert, expect} from "chai";
import * as Sinon from "sinon";
import * as Proxyquire from "proxyquire";
import {EXPRESS_REQUEST} from "../../../../../src/mvc/constants/index";

const ParamRegistry: any = {useService: Sinon.stub(), useFilter: Sinon.stub()};

const {Request} = Proxyquire.load("../../../../../src/mvc/decorators/param/request", {
    "../../registries/ParamRegistry": {ParamRegistry}
});

class Test {

}

describe("Request", () => {

    describe("as parameter decorator", () => {
        before(() => {
            Request()(Test, "test", 0);
            this.args = ParamRegistry.useService.args[0];
        });

        it("should call registry method", () => {
github TypedProject / ts-express-decorators / test / units / mvc / decorators / params / endpointInfo.spec.ts View on Github external
import {assert, expect} from "chai";
import * as Sinon from "sinon";
import * as Proxyquire from "proxyquire";
import {ENDPOINT_INFO} from "../../../../../src/mvc/constants/index";

const ParamRegistry: any = {useService: Sinon.stub(), useFilter: Sinon.stub()};

const {EndpointInfo} = Proxyquire.load("../../../../../src/mvc/decorators/param/endpointInfo", {
    "../../registries/ParamRegistry": {ParamRegistry}
});

class Test {

}

describe("EndpointInfo", () => {

    describe("as parameter decorator", () => {
        before(() => {
            EndpointInfo()(Test, "test", 0);
            this.args = ParamRegistry.useService.args[0];
        });

        it("should call registry method", () => {
github TypedProject / ts-express-decorators / test / units / mvc / decorators / params / responseData.spec.ts View on Github external
import {assert, expect} from "chai";
import * as Sinon from "sinon";
import * as Proxyquire from "proxyquire";
import {RESPONSE_DATA} from "../../../../../src/mvc/constants/index";

const ParamRegistry: any = {useService: Sinon.stub(), useFilter: Sinon.stub()};

const {ResponseData} = Proxyquire.load("../../../../../src/mvc/decorators/param/responseData", {
    "../../registries/ParamRegistry": {ParamRegistry}
});

class Test {

}

describe("ResponseData", () => {

    describe("as parameter decorator", () => {
        before(() => {
            ResponseData()(Test, "test", 0);
            this.args = ParamRegistry.useService.args[0];
        });

        it("should call registry method", () => {
github standard-things / esm / test / fixture / scenario / proxyquire / index.js View on Github external
import assert from "assert"
import proxyquire from "proxyquire"

const a = proxyquire
  .load("./a.js", {
    path: {
      extname: () => "c"
    },
    "./b.js": "b"
  })

assert.strictEqual(a.default(), "abc")
github havsar / node-ts-cache / src / storages / RedisStorage.spec.ts View on Github external
const clientMock = {
            flushdbAsync: Sinon.stub().rejects(new Error('Redis connection failed')),
            setItem: Sinon.fake(),
            delAsync: Sinon.fake(),
            getAsync: Sinon.fake()
        }
        const RedisMock = {
            createClient: () => clientMock,
            RedisClient: {
                prototype: {}
            },
            Multi: {
                prototype: {}
            }
        }
        const MockRedisFailStorage: typeof RedisStorage = Proxyquire.load('./RedisStorage', {
            'redis': RedisMock
        }).RedisStorage

        const testStorage = new MockRedisFailStorage({
            host: 'unknown-host',
            port: 123,
            password: 'pass',
            connect_timeout: 1000
        })

        const errorMsg = 'Should have thrown an error, but did not'
        try {
            await testStorage.clear()
            await Promise.reject(errorMsg)
        } catch (error) {
            if (error === errorMsg) {

proxyquire

Proxies nodejs require in order to allow overriding dependencies during testing.

MIT
Latest version published 5 years ago

Package Health Score

74 / 100
Full package analysis