JavaScript Conventions
If you are using Visual Studio Code then
download and install these two extensions.
Some people follow indentation of 4 spaces. But in BigBinary, we follow
indentation of 2 spaces consistently.
Here are the conventions we would be following regarding the naming of variables and their usage.
- Variables should always be in lower camel case. e.g.
const firstName = Oliver
- When declaring the variables prefer using
const
instead of let
.
let
can be used when we are modifying the variable. If we are modifying the
object or an array const
can still be used instead of let
.
- Commenting involves placing human readable descriptions inside test files
describing what the test is about.
- Sometimes the tests can be quite large and long-winded that its actual
function and use is not quite so apparent from the code itself. In such cases
adding a comment describing the same would improve code readability vastly.
- When writing a comment we must ensure that it is meaningful and we must
always use lowercase alphabets and keep some space after comment.
File Naming Conventions
- The name of the file must convey the test suite name. e.g. If we are adding
test case file for login, name of file should be: login.spec.js
- All the spec files should be stored in e2e folder.
- Follow
JavaScript
conventions for naming the files(i.e lowerCamelCase). e.g.
If we are creating spec file for creating a customer, the name of spec file
should be: createCustomer.spec.js
- The texts and selectors folder should be stored in constants
folder. Their corresponding file names should also be in
lowerCamelCase.
e.g. Selectors:- login.js contained within constants/selectors
.
e.g. Texts:- members.js contained within constants/texts
.
Function arguments conventions
Consider there is function which accepts more than 2 arguments. The challenge with functions like these is that we need to remember the order of their parameters.
Additionally, we might not always need to provide values for all parameters, which can lead to situations where we have to pass null
values just to maintain the parameter order.
In this case, even if I just want to pass the email
and isAdmin
parameters,
I have to pass the password also. So the better approach in this case is to
define the argument as an object.
Now the code is more readable and we can pass only the needed parameters.