Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@aesop-fables/containr-testing
Advanced tools
Testing support (utilities, pattern examples) for containr
containr-testing
provides testing support when using containr
for development.
npm install @aesop-fables/containr-testing
yarn add @aesop-fables/containr-testing
One of the most common testing patterns (when using dependency injection) leverages mocks and/or stubs (we're generalizing quite a bit here). containr-testing
provides the InteractionContext<T>
class that allows you
to automatically generate mocks for your dependencies using jest-mock-extended
.
// MyEntityService.ts
import { inject } from '@aesop-fables/containr';
export interface IEvent {
correlationId: string;
}
export interface IEventPublisher {
publish(event: IEvent): Promise<void>;
}
export const MyServices = {
Publisher: 'publisher',
};
export class MyEntityService implements IEntityService {
constructor(
@inject(MyServices.Publisher) private readonly publisher: IEventPublisher,
) {}
createEntity(name: string): Promise<void> {
const entity = {
id: 'you would probably generate this',
name,
};
await this.publisher.push({
correlationId: entity.id,
});
}
}
// MyEntityService.test.ts
import { IEventPublisher, MyEntityService, MyServices } from './MyEntityService';
import { createInteractionContext, InteractionContext } from '@aesop-fables/containr-testing';
describe('InteractionContext example', () => {
let context: InteractionContext<MyEntityService>;
beforeEach(() => {
// This will automatically configured the context
context = createInteractionContext(MyEntityService);
// If you need to modify the underlying collection
// You can do it - only if you do it BEFORE you call `context.classUnderTest`
// Calls to `context.services` will reset the instance of classUnderTest as well as the underlying service container (if it's already been instantiated)
});
test('demo auto-mocking', async () => {
// classsUnderTest is lazily evaluated and is only instantiated once (the first time you call the property)
await context.classUnderTest.createEntity('Hello');
// the context allows you to retrieve the mocks
// You could obviously inspect the invocation and do more elaborate assertions
expect(context.mockFor<IEventPublisher>(MyServices.Publisher).publish).toBeCalledTimes(1);
});
});
FAQs
Testing support (utilities, pattern examples) for containr
We found that @aesop-fables/containr-testing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.