How to use the jest-mock.spyOn function in jest-mock

To help you get started, we’ve selected a few jest-mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikechabot / redux-entity / test / unit / test-thunk.js View on Github external
it('Stage AFTER_SUCCESS', (done) => {
                const afterSuccess = {
                    _runAfterSuccess(dispatch, getState, data) {
                        return dispatch({type: 'foo', data});
                    }
                };

                const spy = mock.spyOn(afterSuccess, '_runAfterSuccess');

                const configOptions = {
                    processors: {
                        [PROCESSOR_STAGE.AFTER_SUCCESS]: afterSuccess._runAfterSuccess
                    }
                };

                // Under test
                store
                    .dispatch(loadEntity(entity, Promise.resolve({}), configOptions))
                    .then(() => {
                        expect(spy).toHaveBeenCalled();
                    })
                    .then(done)
                    .catch(done);
            });
github mikechabot / redux-entity / test / unit / test-thunk.js View on Github external
it('Stage BEFORE_SUCCESS', (done) => {
                const beforeSuccess = {
                    _runBeforeSuccess(dispatch, getState, data) {
                        return dispatch({type: 'foo', data});
                    }
                };

                const spy = mock.spyOn(beforeSuccess, '_runBeforeSuccess');

                const configOptions = {
                    processors: {
                        [PROCESSOR_STAGE.BEFORE_SUCCESS]: beforeSuccess._runBeforeSuccess
                    }
                };

                // Under test
                store
                    .dispatch(loadEntity(entity, Promise.resolve({}), configOptions))
                    .then(() => {
                        expect(spy).toHaveBeenCalled();
                    })
                    .then(done)
                    .catch(done);
            });
github mikechabot / redux-entity / test / unit / test-thunk.js View on Github external
it('Stage BEFORE_FAILURE', (done) => {
                const beforeFailure = {
                    _runBeforeFailure(dispatch, getState, data) {
                        return dispatch({type: 'foo', data});
                    }
                };

                const spy = mock.spyOn(beforeFailure, '_runBeforeFailure');

                const configOptions = {
                    processors: {
                        [PROCESSOR_STAGE.BEFORE_FAILURE]: beforeFailure._runBeforeFailure
                    }
                };

                // Under test
                store
                    .dispatch(loadEntity(entity, Promise.reject(new Error('Fake error')), configOptions))
                    .catch(() => {
                        expect(spy).toHaveBeenCalled();
                        done();
                    });
            });
            it('Stage BEFORE_FAILURE should return a new object', (done) => {
github mikechabot / redux-entity / test / unit / test-thunk.js View on Github external
it('Stage AFTER_FAILURE', (done) => {
                const afterFailure = {
                    _runAfterFailure(dispatch, getState, data) {
                        return dispatch({type: 'foo', data});
                    }
                };

                const spy = mock.spyOn(afterFailure, '_runAfterFailure');

                const configOptions = {
                    processors: {
                        [PROCESSOR_STAGE.BEFORE_FAILURE]: afterFailure._runAfterFailure
                    }
                };

                // Under test
                store
                    .dispatch(loadEntity(entity, Promise.reject(new Error('Fake Error')), configOptions))
                    .catch(() => {
                        expect(spy).toHaveBeenCalled();
                        done();
                    });
            });
        });

jest-mock

**Note:** More details on user side API can be found in [Jest documentation](https://jestjs.io/docs/mock-function-api).

MIT
Latest version published 8 months ago

Package Health Score

93 / 100
Full package analysis