How to use the ts-jest/utils.mocked function in ts-jest

To help you get started, we’ve selected a few ts-jest 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 CityOfZion / neon-js / packages / neon-api / __tests__ / func / fill.ts View on Github external
import { wallet } from "@cityofzion/neon-core";
import { mocked } from "ts-jest/utils";
import { SendAssetConfig } from "../../lib/funcs/types";
import * as fill from "../../src/funcs/fill";
import { signWithPrivateKey as _signWithPrivateKey } from "../../src/funcs/sign";
import { ClaimGasConfig } from "../../src/funcs/types";

jest.mock("../../src/funcs/sign");

const signWithPrivateKey = mocked(_signWithPrivateKey, false);

describe("fillUrl", () => {
  test("skips if url present", async () => {
    const expectedUrl = "http://localhost.com";
    const config = {
      api: {
        getRPCEndpoint: jest.fn()
      } as any,
      account: {},
      url: expectedUrl
    } as SendAssetConfig;

    const result = await fill.fillUrl(config);

    expect(result.url).toBe(expectedUrl);
    expect(config.api.getRPCEndpoint).not.toBeCalled();
github CityOfZion / neon-js / packages / neon-api / __tests__ / func / mint.ts View on Github external
import { tx } from "@cityofzion/neon-core";
import { mocked } from "ts-jest/utils";
import { getVerificationSignatureForSmartContract as _getVerificationSignatureForSmartContract } from "../../src/funcs/common";
import * as mint from "../../src/funcs/mint";
import { DoInvokeConfig } from "../../src/funcs/types";

jest.mock("../../src/funcs/common");

const getVerificationSignatureForSmartContract = mocked(
  _getVerificationSignatureForSmartContract,
  false
);

describe("addAttributeForMintToken", () => {
  test("skips if no script object present", async () => {
    const config = {
      tx: new tx.ContractTransaction({} as any)
    } as DoInvokeConfig;

    const result = await mint.addAttributeForMintToken(config);

    expect(result.tx!.attributes.length).toBe(0);
  });

  test("adds attribute if script object present", async () => {
github mlaursen / react-md / packages / documentation / src / components / DemoSandbox / __tests__ / DemoSandbox.tsx View on Github external
import React from "react";
import { mocked } from "ts-jest/utils";
import { render, fireEvent } from "utils/tests";

import DemoSandbox from "../DemoSandbox";
import useSandbox from "../useSandbox";

jest.mock("../useSandbox");

const useSandboxMock = mocked(useSandbox);

beforeEach(() => {
  useSandboxMock.mockImplementation(defaultSandbox => ({
    sandbox: defaultSandbox,
    loading: false,
  }));
});

describe("DemoSandbox", () => {
  it("should not return to a from url that does not start with /packages so malicious urls can't be returned to", () => {
    const sandbox = {};
    const push = jest.fn();
    const router = {
      push,
      query: {
        pkg: "tree",
github CityOfZion / neon-js / packages / neon-core / __tests__ / sc / core.ts View on Github external
import { mocked } from "ts-jest/utils";
import { createScript, generateDeployScript } from "../../src/sc/core";
import _ScriptBuilder from "../../src/sc/ScriptBuilder";
import * as _u from "../../src/u";
import testIntents from "./scriptIntents.json";

jest.mock("../../src/sc/ScriptBuilder");
jest.mock("../../src/u");

const ScriptBuilder = mocked(_ScriptBuilder, true);
const u = mocked(_u, false);

beforeEach(() => {
  jest.clearAllMocks();
});

describe("createScript", () => {
  test("single ScriptIntent", () => {
    const intent = testIntents[1].scriptIntent;
    const result = createScript(intent);
    expect(ScriptBuilder).toHaveBeenCalledTimes(1);
    const sb = ScriptBuilder.mock.instances[0];
    expect(sb.emitAppCall).toBeCalledWith(
      intent.scriptHash,
      intent.operation,
      intent.args,
      false
github mlaursen / react-md / packages / utils / src / __tests__ / useInterval.tsx View on Github external
import React, { FC } from "react";
import { act, renderHook } from "@testing-library/react-hooks";
import { render } from "@testing-library/react";
import { mocked } from "ts-jest/utils";

import useInterval from "../useInterval";

jest.useFakeTimers();
const setInterval = mocked(window.setInterval);
const clearInterval = mocked(window.clearInterval);
beforeEach(() => {
  setInterval.mockClear();
  clearInterval.mockClear();
});

interface TestProps {
  cb: () => void;
  delay?: number;
  defaultRunning?: boolean;
}

const Test: FC = ({ cb, delay = 300, defaultRunning = false }) => {
  useInterval(cb, delay, defaultRunning);
  return null;
};
github Nevoss / form-wrapper-js / tests / unit / core / FormCollection.spec.ts View on Github external
expect(formCollection.clear).toHaveBeenCalledTimes(1)
    expect(formCollection.all().length).toBe(3)
    expect(formCollection.getInitialFormsIds()).toEqual([])
    formCollection.all().forEach(
      (form: Form, index): void => {
        expect(fillSpy).toHaveBeenNthCalledWith(
          index + 1,
          mockValues[index],
          false,
          true
        )
      }
    )

    mocked(fillSpy).mockClear()
  })
github tom-grey / typedoc-plugin-markdown / src / lib / theme / helpers / project-title.spec.ts View on Github external
test(`should return empty for GitbookTheme`, () => {
    mocked(MarkdownPlugin).theme = new GitbookTheme({} as Renderer, '/', {});
    const data = {
      project: {
        name: 'Project title',
      },
      model: {
        name: 'Reflection title',
      },
    };
    const result = projectTitle.call(data);
    expect(result).toEqual('');
  });
});
github tom-grey / typedoc-plugin-markdown / src / lib / theme / helpers / project-title.spec.ts View on Github external
test(`should compile`, () => {
    mocked(Handlebars).helpers.relativeURL = () => {
      return 'url';
    };
    mocked(MarkdownPlugin).settings = { hideProjectTitle: false };
    mocked(MarkdownPlugin).theme = { indexName: 'pagex.md' } as MarkdownTheme;
    const data = {
      project: {
        name: 'Project title',
      },
      model: {
        name: 'Reflection title',
      },
    };
    const result = projectTitle.call(data);
    expect(result).toMatchSnapshot();
  });
github commercetools / merchant-center-application-kit / packages / sdk / src / middleware / middleware.spec.ts View on Github external
beforeEach(() => {
        execute = jest.fn(() => Promise.resolve(response));
        mocked(createClient).mockReturnValue({
          execute,
        });

        resultPromise = createMiddleware(middlewareOptions)({
          dispatch,
          getState: jest.fn(),
        })(next)(action);
      });