@dudousxd/nestjs-inertia-testing
v1.4.2
Published
Testing helpers for @dudousxd/nestjs-inertia — expectInertia matchers, fakes, TestingModule.
Downloads
2,035
Readme
@dudousxd/nestjs-inertia-testing
Testing helpers for
@dudousxd/nestjs-inertia—expectInertia(res)matchers, fakes,InertiaTestingModule.
Install
pnpm add -D @dudousxd/nestjs-inertia-testingFluent matcher (any test framework)
import { expectInertia } from '@dudousxd/nestjs-inertia-testing';
const res = await request(app.getHttpServer()).get('/dashboard').set('X-Inertia', 'true');
expectInertia(res)
.toRenderComponent('Dashboard')
.toHaveProp('user.id', 42)
.toHavePropMatching('user.email', /@goflip\.ai$/)
.toHaveUrl('/dashboard');Full API: toRenderComponent, toHaveProp, toHavePropMatching, toMissProp, toHaveExactProps, toShareProp, toHaveUrl, toHaveVersion, toHaveDeferredProp, toHaveMergeProp, toRedirectExternal, toRedirectTo, toHaveErrors, toHaveErrorBag, toRenderFullHtml, withSsrHead, pageObject(), unwrap().
Jest / Vitest matchers (expect.extend)
Add to your test setup file:
// vitest.setup.ts (or jest.setup.ts)
import '@dudousxd/nestjs-inertia-testing/vitest'; // or /jestThen:
expect(res).toRenderInertiaComponent('Dashboard');
expect(res).toHaveInertiaProp('user.id', 42);Controller-level tests with InertiaTestingModule
import { InertiaTestingModule } from '@dudousxd/nestjs-inertia-testing';
const moduleRef = await Test.createTestingModule({
imports: [InertiaTestingModule.forTest({ version: 'test-v1' })],
controllers: [DashboardController],
}).compile();Plain assert (no framework)
import { assertInertia } from '@dudousxd/nestjs-inertia-testing';
assertInertia(payload).toRenderComponent('Dashboard');License
MIT
