Skip to content

Instantly share code, notes, and snippets.

@surajtruckx
Created February 22, 2021 09:03
Show Gist options
  • Save surajtruckx/71b51ad4d7ab09b42124446ae0c19063 to your computer and use it in GitHub Desktop.
Save surajtruckx/71b51ad4d7ab09b42124446ae0c19063 to your computer and use it in GitHub Desktop.
Integration Test Format with expectSaga()
describe(`functionName()`, () => {
afterEach(() => {
//clean up after every `it` block
});
describe(`When …. specify the external state you want to test against`, () => {
beforeEach(() => {
// setup the external state, ex: populate db, async storage etc
});
it(`Should ... set the expectations`, () => {
//expectSaga()...
});
});
describe(`When …. specify the external state you want to test against`, () => {
beforeEach(() => {
// setup the external state, ex: populate db, async storage etc
});
it(`Should ... set the expectations`, () => {
//expectSaga()...
});
});
}):
//Example:
import { expectSaga } from 'redux-saga-test-plan';
import Sentry from '@sentry/react-native';
import { SENTRY_DSN } from 'react-native-dotenv';
import { call } from 'redux-saga/effects';
jest.mock('react-native-dotenv');
export function* startSentryLogging() {
const { ENV } = require('react-native-dotenv');
if (ENV !== 'production') {
return false;
}
// @ts-ignore
yield call(Sentry.init, { dns: SENTRY_DSN });
}
describe('startSentryLogging', () => {
afterEach(() => {
require('react-native-dotenv').ENV = '';
// @ts-ignore
jest.clearAllMocks();
});
describe('when ENV is production', () => {
beforeEach(() => {
require('react-native-dotenv').ENV = 'production';
});
it('should call Sentry.init', function () {
return expectSaga(startSentryLogging)
.call(Sentry.init, { dns: SENTRY_DSN })
.run();
});
});
describe('when ENV is not production', () => {
beforeEach(() => {
require('react-native-dotenv').ENV = 'development';
});
it('should not call Sentry.init', function () {
return expectSaga(startSentryLogging)
.run()
.then(() => {
expect(Sentry.init).not.toHaveBeenCalled();
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment