Posts

Showing posts from 2019

Unit Test: React-Bootstrap Modal

Writing unit test always help in longer run. Now a days almost all frameworks and libraries are supporting unit testing. In React Bootstrap, there is documentation for using the unit test cases but still writing unit test cases for React-Bootstrap Modal can get confusing. After spending hours on it finally I am able to write test cases for it. These code snippets can be used for other React-Bootstrap components as well (by changing the corresponding names). Modal Source code: import React from 'react'; import Container from 'react-bootstrap/Container'; import './uv-modal.css'; function UVModal(props) { return ( <Modal {...props} aria-labelledby="contained-modal-title-vcenter"> <Modal.Header closeButton> <Modal.Title id="contained-modal-title-vcenter"> Modal Title </Modal.Title> </Modal.Header> <Modal.Body> <Containe...

JavaScript Best Practices

Getting things done is good but getting things done in better way is what matters most. Everyone wants to make their website/application to be faster, lighter. No one likes slow website/application. In order to make website/application we have to set some best practices standards and every teammate should follow that. I have written down few of the best practices which I recommend to be followed in any JavaScript development. Use === Instead of == Eval = Evil Don't use short-hand                      Bad Recommended if(condition) x = false; if(condition){ x = false; } Place scripts at the bottom of your page. The fastest way to build a HTML list. var arr = ['item 1', 'item 2', 'item 3', ...]; var list = '<ul><li>'+arr.join('</li><li>')+'</li></ul>'; Reduce global variables and methods. Add comme...

Cheat Sheet - Jasmine

We reuse many things during any application development. While working with Jasmine, generally there two sources, Jasmine Docs or Google. Even though we refer these resources, it consumes lot of time to get what we want i.e. right syntax and example. To avoid doing this every time I have enlisted few of them as cheat sheet which can be used whenever required. Create spy object with spy methods mySpy = jasmine.createSpyObj('Contact', ['get','set']); Call fake method instead of real one. mySpy.pickContact.and.callFake(function () { return { id: 10 }; }); Call a spy method and return a value var contact = { id: 10 }; mySpy.pickContact.and.returnValue(contact); Call a spy method and return a async value var contact = { id: 10 }; mySpy.pickContact.and.returnValue(asyncData(contact)); Check call counts expect(mySpy.get.calls.count()).toBe(1, 'one call'); Check most recent call expect(mySpy.get.calls.mo...

Cheat Sheet - Git

While working with Git, generally there three sources, Git Official Docs , Bitbucket Docs   or Google. Even though we refer these resources, it consumes lot of time to get what we want i.e. right syntax and example. To avoid doing this every time I have enlisted few of them as cheat sheet which can be used whenever required. Initialize git repo $ git init Set User Name and Email Id $ git config --global user.name "<user_name>" $ git config --global user.email "<user_email_id>" List Global Settings $ git config --global --list Push all changed files $ git add . $ git commit –m "<commit_message>" $ git push origin <remote_branch_name> Push a specific commit $ git push origin <commit_SHA_id>:master Stash the changes. $ git stash save "<stash_message>" Get list of stash. $ git stash list Pop last stash $ git stash pop Pop a particular stash. ( Recommended )               Use ...