Miss any of our Open RFC calls?Watch the recordings here! »

event-store-projection-testing

2.0.1 • Public • Published

Framework agnostic unit testing utility for Event Store projections

Usage

Add utility to projection

var fromAll = fromAll || require('event-store-projection-testing').scope.fromAll;
var emit = emit || require('event-store-projection-testing').scope.emit;
 
fromAll()
  .when({...});

Start testing

require('chai').should();
var projection = require('event-store-projection-testing');
require('./projection');
 
describe('Projection tests', function() {
  beforeEach(function() {
    projection.initialize();
  });
 
  it('should increment balance on cashDeposited event when initial balance is set', function() {
    projection.setState({balance: 10});
    projection.processEvent('stream-123', 'cashDeposited', {deposit: 10});
    projection.getState().balance.should.equal(20);
  });
 
  it('should increment balance on cashDeposited event without initial balance', function() {
    projection.processEvent('stream-123', 'cashDeposited', {deposit: 10});
    projection.getState().balance.should.equal(10);
  });
 
  it('should not increment balance on unregistered event', function() {
    projection.processEvent('stream-123', 'NON_EXISTING_EVENT_TYPE', {deposit: 10});
    projection.getState().balance.should.equal(0);
  });
 
  it('should increment counter for every event', function() {
    projection.processEvent('stream-123', 'cashDeposited', {deposit: 10});
    projection.processEvent('stream-123', 'NON_EXISTING_EVENT_TYPE', {deposit: 10});
    projection.getState().counter.should.equal(2);
  });
 
  it('should re-emit all cashDeposited events', function() {
    projection.processEvent('stream-123', 'cashDeposited', {deposit: 10});
    projection.processEvent('stream-123', 'cashDeposited', {deposit: 10});
    projection.processEvent('stream-123', 'cashDeposited', {deposit: 10});
    projection.emittedEvents.should.have.length(3);
  });
});

More complete instructions available on my blog

Install

npm i event-store-projection-testing

DownloadsWeekly Downloads

8

Version

2.0.1

License

MIT

Unpacked Size

34.1 kB

Total Files

9

Last publish

Collaborators

  • avatar