All Questions
Tagged with unit-testing javascript
88 questions
-1
votes
1
answer
210
views
Test the log in functionality of a web page with incorrect credentials [closed]
I'm new to playwright, so I'm unsure if this is the correct or best way to go about testing. I basically want multiple tests on the same webpage. I've been able to successfully accomplish this using ...
0
votes
1
answer
145
views
Six different, concise (and hopefuly readable), sorting algorithms using ES6+ idioms, with some basic unit testing
I'm practicing js, unit testing, and algorithms, so implementing some of the common sorting algorithms and doing some basic unit testing on them seemed like a good exercise.
I'm also trying to use ...
0
votes
1
answer
415
views
Sanitize object to only include specific properties
Object Property Sanitization
I'm learning to code servers using JavaScript, Node, and Express. While writing controllers that create new entries in the database, the need to sanitize the user input ...
1
vote
1
answer
419
views
Unit tests for individual methods of a calculator
Recently I needed to expand the exports in a file to all methods in order to allow for Jest tests to cover more of the code (without using Rewire). Beforehand, only the functions used by other ...
3
votes
0
answers
125
views
Testing a javascript function that performs side effects
Application context
I am working on a game I call "Apes and Snakes". So far the code only allows players to connect to a host using a room code and WebRTC. Players and the host send messages ...
4
votes
0
answers
1k
views
Jest - mocking a class function from an external node module
I am writing unit tests for a NestJS service, which imports and instantiates a class (OAuth2Client) from an external module (google-auth-library) and uses one of its functions (verifyIdToken).
I am ...
2
votes
0
answers
73
views
Express compatible JSON Web Token authentication middleware
I am writing an Express.js middleware function in a TypeScript NodeJS project that uses a function from a third-party module to perform a small workload. When writing unit tests, I want to mock this ...
1
vote
1
answer
74
views
3
votes
0
answers
119
views
NavigationBar component with hooks. Can it be made more readable/maintainable?
I wrote a NavigationBar component in React, using hooks, react-bootstrap, react-i18next and css. Now the component works as I expect it, but the code seems ugly. (I'm new with hooks)
Features:
It's ...
3
votes
1
answer
121
views
Correct way to unit-test express API
I wrote an express API for a document management service (repo to be found here) and even though I understand the importance of unit-testing I never quite managed to wrap my head around how I would ...
7
votes
1
answer
418
views
Vue component for Game Die (dice)
As part of learning Vue and Vue Test Utils I develop some simple games. I made a simple version of craps. Because in many other games a die (or dice) is used, I decided to create a reusable component <...
0
votes
1
answer
193
views
Asking for test: Calculator function javascript
I have made a code that can run a calculation from text. When I tested it, I didn't find any bugs. You are sharper than me. Maybe you can discover some bugs in this code. When you know some ...
7
votes
2
answers
2k
views
Move all zeros to the left with TDD approach
The task
Given an integer array, move all elements that are equal to 0 to the
left while maintaining the order of other elements in the array. Let's
look at the following integer array.
...
1
vote
1
answer
66
views
Creating a real unit test in Karma for Angular code [closed]
This is a piece of test code made for the Angular application.
The router object is a mock provided by the RouterTestingModule dependency. I wonder if such a test can be considered a unit test (...
3
votes
0
answers
347
views
JavaScript `localStorage` with `document.cookie` fallback for static web sites
The Code
I've got things operating as desired so far and am hoping fresh eyes can point out any mistakes or bits that can be improved, a live demo is hosted and updated on GitHub Pages, Travis-CI ...