Skip to content

Commit

Permalink
Accept empty arguments in the constructor (#51)
Browse files Browse the repository at this point in the history
Simplify the usage in the case of no arguments. Instead of
`new SagaTester({})` you can now say `new SagaTester()`.
  • Loading branch information
apaatsio authored and InterAl committed Mar 24, 2019
1 parent 79ce304 commit 1d5db5a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions examples/example.multiple.waitfor.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('example.multiple.waitfor.js', () => {
.reply(200, fetchReply);

// Start up the saga tester
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();

sagaTester.start(mySagaSync);

Expand Down Expand Up @@ -80,7 +80,7 @@ describe('example.multiple.waitfor.js', () => {
.reply(200, fetchReply);

// Start up the saga tester
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();

sagaTester.start(mySagaAsync);

Expand Down
2 changes: 1 addition & 1 deletion examples/example.nock.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('example.nock.js', () => {
.reply(200, fetchReply);

// Start up the saga tester
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();

sagaTester.start(mySaga);

Expand Down
2 changes: 1 addition & 1 deletion src/SagaTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class SagaIntegrationTester {
combineReducers = reduxCombineReducers,
ignoreReduxActions = true,
options = {},
}) {
} = {}) {
this.calledActions = [];
this.actionLookups = {};
this.sagaMiddleware = createSagaMiddleware(options);
Expand Down
36 changes: 22 additions & 14 deletions test/SagaTester.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ describe('SagaTester', () => {
);
});

it('Accepts empty arguments', () => {
expect(() => new SagaTester()).not.to.throw();
});

it('Accepts an empty object as an argument', () => {
expect(() => new SagaTester({})).not.to.throw();
});

it('Populates store with a given initial state', () => {
const sagaTester = new SagaTester({initialState : someInitialState});
expect(sagaTester.getState()).to.deep.equal(someInitialState);
});

it('Saves a list of actions and returns it in order', () => {
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
sagaTester.dispatch(someAction);
sagaTester.dispatch(otherAction);
expect(sagaTester.getCalledActions()).to.deep.equal([
Expand All @@ -47,7 +55,7 @@ describe('SagaTester', () => {
});

it('Ignores redux action types by default', () => {
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
sagaTester.dispatch(reduxAction);
expect(sagaTester.getCalledActions()).to.deep.equal([]);
});
Expand Down Expand Up @@ -96,7 +104,7 @@ describe('SagaTester', () => {
const sagas = function*() {
yield flag = true;
};
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
const task = sagaTester.start(sagas);
expect(task).to.be.an('object');
expect(flag).to.equal(true);
Expand All @@ -107,7 +115,7 @@ describe('SagaTester', () => {
const sagas = function*() {
yield flag = true;
};
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
const promise = sagaTester.run(sagas);
expect(promise).to.be.a('promise');
expect(flag).to.equal(true);
Expand Down Expand Up @@ -165,20 +173,20 @@ describe('SagaTester', () => {
});

it('Returns whether or not an action was called', () => {
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
expect(sagaTester.wasCalled(someActionType)).to.equal(false);
sagaTester.dispatch(someAction);
});

it('Returns whether or not an action was called (including a waitFor clause)', () => {
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
sagaTester.waitFor(someActionType);
expect(sagaTester.wasCalled(someActionType)).to.equal(false);
sagaTester.dispatch(someAction);
});

it('Counts and returns the number of times an action was called', () => {
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
expect(sagaTester.numCalled(someActionType)).to.equal(0);
sagaTester.dispatch(someAction);
expect(sagaTester.numCalled(someActionType)).to.equal(1);
Expand All @@ -187,19 +195,19 @@ describe('SagaTester', () => {
});

it('Returns a promise that will resolve in the future when a specific action is called', done => {
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
sagaTester.waitFor(someActionType).then(() => done());
sagaTester.dispatch(someAction);
});

it('Returns a resolved promise when a specific action was already called', done => {
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
sagaTester.dispatch(someAction);
sagaTester.waitFor(someActionType).then(() => done());
});

it('Returns a promise that will resolve in the future even after an action was called', () => {
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
sagaTester.dispatch(someAction);
const promise = sagaTester.waitFor(someActionType, true);
return expect(Promise.race([promise, Promise.resolve('fail')])).to.eventually.equal('fail').then(() => {
Expand All @@ -209,7 +217,7 @@ describe('SagaTester', () => {
});

it('Rejects if saga completes without emiting awaited action', () => {
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
const NON_EMITTED_ACTION = 'NON_EMITTED_ACTION';
const emptySaga = function*() {
yield;
Expand All @@ -226,15 +234,15 @@ describe('SagaTester', () => {
yield;
throw new Error(reason);
};
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
sagaTester.run(sagas);

const promise = sagaTester.waitFor(someActionType);
return expect(promise).to.be.rejectedWith(Error, reason);
});

it('Gets the latest called action', () => {
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
sagaTester.dispatch(someAction);
sagaTester.dispatch(otherAction);

Expand All @@ -246,7 +254,7 @@ describe('SagaTester', () => {
});

it('Gets the latest called actions', () => {
const sagaTester = new SagaTester({});
const sagaTester = new SagaTester();
sagaTester.dispatch(someAction);
sagaTester.dispatch(otherAction);

Expand Down

0 comments on commit 1d5db5a

Please sign in to comment.