@rhangai/nest-testing
v0.9.2
Published
Nest test services module
Downloads
53
Readme
@rhangai/nest-testing
Installation
yarn add @rhangai/nest-testing @nestjs/testing jest
Usage
Create your test factory
import { createTestFactory } from '@rhangai/nest-testing';
export const createTest = createTestFactory({
imports: [],
plugins: [],
});
Create a test
import { createTest } from './somewhere';
import { SomethingService } from './some.service';
describe('MyService', () => {
const t = createTest({
services: {
something: SomethingService,
},
});
it('should do something', () => {
t.services.something.doSomething();
});
});
Plugins
e2e
Setup
import { testPluginE2e } from '@rhangai/nest-testing/lib/e2e';
export const createTest = createTestFactory({
plugins: [testPluginE2e()],
});
Usage
t.e2t((e2e) => {
it('graphql', () => {
await e2e.graphql({
query: (gql) => gql`
query ($id: Int!) {
item(id: $id) {
id
name
}
}
`,
variables: {
id: 1,
},
expect: {
item: {
id: 1,
name: 'Box',
},
},
});
});
});
typeorm
Setup
import { testPluginTypeorm } from '@rhangai/nest-testing/lib/typeorm';
export const createTest = createTestFactory({
plugins: [testPluginTypeorm()],
});
Usage
Now you can use the typeorm module
const entities = await t.entityManager.find(EntityClass);