How to use the ts-mock-imports.ImportMock.mockOther function in ts-mock-imports

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 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();
  });

ts-mock-imports

Intuitive mocking for Typescript class imports

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis