How to use ts-mock-imports - 8 common examples

To help you get started, we’ve selected a few ts-mock-imports 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 naver / egjs-flicking / test / unit / options.spec.ts View on Github external
it("should init with collectStatistics(true)", () => {
      // Given
      const mockGa = ImportMock.mockFunction(ga, "sendEvent");

      // When
      flickingInfo = createFlicking(horizontal.full, { collectStatistics: true });
      mockGa.restore();

      // Then
      expect(mockGa.callCount).to.be.equals(1);
    });
  });
github pact-foundation / pact-js / src / httpPact.spec.ts View on Github external
before(() => {
    // Stub out pact-node
    const manager = ImportMock.mockClass(serviceFactory, "createServer") as any
    manager.mock("createServer", () => {})
  })
github authelia / authelia / server / src / lib / routes / verify / Get.spec.ts View on Github external
it('should redirect user to login portal', async function() {
      req.headers['proxy-authorization'] = 'zglfzeljfzelmkj';
      req.query.rd = 'https://login.example.com/';
      const mock = ImportMock.mockOther(GetBasicAuth, "default", () => Promise.reject(new NotAuthenticatedError('No!')));
      await Get(vars)(req, res as any);
      Assert(res.redirect.calledWith('https://login.example.com/?rd=https://secret.example.com/'));
      mock.restore();
    });
  });
github authelia / authelia / server / src / lib / routes / verify / Get.spec.ts View on Github external
it('should allow access to user', async function() {
      const mock = ImportMock.mockOther(GetSessionCookie, "default", () => Promise.resolve());
      await Get(vars)(req, res as any);
      Assert(res.send.calledWithExactly());
      Assert(res.status.calledWithExactly(204))
      mock.restore();
    });
  });
github authelia / authelia / server / src / lib / routes / verify / GetBasicAuth.spec.ts View on Github external
it('should fail when authorizations are not sufficient', function() {
    req.headers['proxy-authorization'] = 'Basic aGVsbG8xOndvcmxkCg==';
    const mock = ImportMock.mockOther(CheckAuthorizations, 'default', () => { throw new Error('Not enough permissions.')});
    mocks.usersDatabase.checkUserPasswordStub.resolves({
      email: 'john@example.com',
      groups: ['group1', 'group2'],
    });
    AssertRejects(async () => await GetBasicAuthModule(req, res as any, vars));
    mock.restore();
  });
github openfun / marsha / src / frontend / components / DashboardVideoPaneTranscriptOption / index.spec.tsx View on Github external
import { fireEvent, render } from '@testing-library/react';
import fetchMock from 'fetch-mock';
import React from 'react';
import { act } from 'react-dom/test-utils';
import { ImportMock } from 'ts-mock-imports';

import { DashboardVideoPaneTranscriptOption } from '.';
import * as useTimedTextTrackModule from '../../data/stores/useTimedTextTrack';
import { timedTextMode, uploadState } from '../../types/tracks';
import { Deferred } from '../../utils/tests/Deferred';
import { wrapInIntlProvider } from '../../utils/tests/intl';

const useTimedTextTrackStub = ImportMock.mockFunction(
  useTimedTextTrackModule,
  'useTimedTextTrack',
);

jest.mock('../../data/appData', () => ({
  appData: {},
}));

describe('', () => {
  afterEach(jest.resetAllMocks);

  afterAll(useTimedTextTrackStub.restore);
  const video = {
    description: 'Some description',
    has_transcript: false,
    id: '443',
github openfun / marsha / src / frontend / components / DashboardThumbnail / index.spec.tsx View on Github external
import { wrapInIntlProvider } from '../../utils/tests/intl';

jest.mock('react-router-dom', () => ({
  Redirect: ({ push, to }: { push: boolean; to: string }) =>
    `Redirect push to ${to}.`,
}));

jest.mock('../../data/appData', () => ({
  appData: {
    jwt: 'some token',
  },
}));

const mockAddThumbnail = jest.fn();

const useThumbnailStub = ImportMock.mockFunction(
  useThumbnailModule,
  'useThumbnail',
);

describe('', () => {
  afterEach(jest.resetAllMocks);

  afterAll(useThumbnailStub.restore);

  const video = {
    description: '',
    has_transcript: false,
    id: '43',
    is_ready_to_show: true,
    show_download: true,
    thumbnail: {
github openfun / marsha / src / frontend / components / VideoPlayer / index.spec.tsx View on Github external
jest.mock('jwt-decode', () => jest.fn());

jest.mock('../../utils/isAbrSupported', () => ({
  isHlsSupported: jest.fn(),
  isMSESupported: jest.fn(),
}));
const mockIsMSESupported = isMSESupported as jestMockOf;
const mockIsHlsSupported = isHlsSupported as jestMockOf;

jest.mock('../../Player/createPlayer', () => ({
  createPlayer: jest.fn(),
}));

const mockCreatePlayer = createPlayer as jestMockOf;

const useTimedTextTrackStub = ImportMock.mockFunction(
  useTimedTextTrackModule,
  'useTimedTextTrack',
);

jest.mock('../../data/appData', () => ({
  appData: {
    video: {
      description: 'Some description',
      id: 'video-id',
      is_ready_to_show: true,
      show_download: false,
      thumbnail: null,
      timed_text_tracks: [],
      title: 'Some title',
      upload_state: 'ready',
      urls: {

ts-mock-imports

Intuitive mocking for Typescript class imports

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis