Socket
Book a DemoInstallSign in
Socket

@chaoyangnz/jest-extension

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chaoyangnz/jest-extension

Jest extension

latest
Source
npmnpm
Version
0.24.2
Version published
Maintainers
1
Created
Source

Jest mock extension

Install

If you are using Jest 23 or lower, please install jest-extension 0.23.x, otherwise, 0.24.x.

Mock a class

This would be useful in Angular and NestJS testing.

Plain class testing:

const SampleServiceMockClass: Type<ClassMock<SampleService>> = mockClass(SampleService);
const sampleServiceMock: ClassMock<SampleService> = new SampleServiceMockClass();

Angular testing:

let cookieService: ClassMock<CookieService>;

beforeEach(async () => {
    TestBed.configureTestingModule({
      providers: [
        TrackingIdService,
        {
          provide: CookieService,
          useClass: mockClass(CookieService)
        }
      ]
    });
    cookieService = TestBed.get(CookieService);
});

NestJS testing:

let module: TestingModule;
let loggerService: ClassMock<LoggerService>;

beforeEach(async () => {
    module = await Test.createTestingModule({
      controllers: [],
      providers: [
        ConfigService,
        {
          provide: LoggerService,
          useClass: mockClass(LoggerService),
        },
      ],
    }).compile();

    loggerService = module.get(LoggerService);
});

Keywords

jest

FAQs

Package last updated on 25 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts