/
githubmirror
/
nest
Обзор
Документация
Войти
/
githubmirror
/
nest
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
sample/34-using-esm-packages/src/app.controller.spec.ts
34 строки
1 KB
Micael Levi L. Cavalcante
chore: add sample on how to use esm on cjs
01 окт 2024, 16:35
01 окт 2024, 16:35
0dafaaa
Код
Авторство
О чём код?
// NOTE: This tests nothing, it's just to show how to mock an ESM package import { jest } from '@jest/globals'; // We will test the mocking feature from Jest to mock the `superjson` package for testing purposes // We must call this before loading the module! jest.unstable_mockModule('superjson', () => ({ stringify: () => 'noop', })); import { Test, TestingModule } from '@nestjs/testing'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { superJSONProvider } from './superjson.provider'; describe('AppController', () => { let appController: AppController; beforeEach(async () => { const app: TestingModule = await Test.createTestingModule({ controllers: [AppController], providers: [superJSONProvider, AppService], }).compile(); appController = app.get<AppController>(AppController); }); describe('root', () => { it('should return the stub object', () => { expect(appController.getHello()).toEqual({ jsonString: 'noop', }); }); }); });