Tuesday, January 10, 2023

How to mock specific method mockImplementation jest in nodejs?

 Here is some best solution , how we can mock specific method from utils file.


Step1: I have created a utils.js file and it contains two methods

like :

const getSchoolName = async ({schoolId }) => {


return 'Bikash School';
};
const getAllSchoolList = async ({schoolId }) => {


return {object};
};


Step 2 : create actual-utils-call.test.js  and import the utils.js file

import { getAllSchoolList, getSchoolName } from './util';



jest.mock('./utils', () => {
const originalUtils = jest.requireActual('./utils');
return {
...originalUtils,
getSchoolName: jest.fn(),
};
});


describe('Mock specific mockImplementation', () => {
it('getSchoolName method should mock from util file', async () => {
getSchoolName.mockImplementation(() => {
return 'different School Name';
});
});

// Here you call your actual method where getSchoolName method is invoke

});

Sunday, November 20, 2022

How to publish the nodeJS custom module version using command steps

 Hi All, please follow below are the steps command to publish the nodeJs custom module version


Follow these steps in order to cut a new version of `@bikash/register`. Through this
step-by-step guide, we will assume that the package is currently at `1.0.6` and that the
new version will be `1.0.7`.

1. Check out a clean version `git checkout master`
2. Pull down changes with `git pull`
3. Determine what the next version will be with `yarn release --dry-run`
4. Create a new release branch based on version from step 3 with `git checkout -b release/1.0.7`
5. Run `yarn release`
6. Check to make sure we have a new tag (`v1.0.7`) and a commit entry
7. Run `git push -u origin release/1.0.7 --follow-tags`
8. Create a new PR to merge `release/1.0.7` into `master`.
9. Merge PR