Richard Kotze

Codewars logo

Agile software engineering

Picture of Richard Kotze
  • Projects
  • Coding
  • Top Tips
  • Fixes

About me | RSS | Helpful links

Unit-testing

Unit test & mock VS Code extension API with Jest

Published Jan 6, 2020

There is an issue with unit testing VS Code extensions. The vscode dependency - which is needed to utilise the editor’s features - will error when running unit tests. Essentially it is a third party dependency which is out of your control, so the best thing to do is to mock the API. I will be using Jest and will explain how to use its mocking features to handle the VS Code dependency.

Mocking React hooks when unit testing using Jest

Published Dec 9, 2019

This won’t be a deep dive into unit testing React components but I will present some options for mocking external services. This is seen as good practice at the unit test level, as we don’t want these tests dependant on an external API which will slow the feedback down and make the test fragile. Mocking is typically used quite loosely and there are plenty of nuances when we throw spies and stubs in the mix. However, they do have a particular meaning and they are all placed under the generic term of Test Double as described by Martin Fowler.

Stub a React component using Sinon

Published Nov 4, 2018

Stubbing a React component is easy with Sinon. You can replace a component with a Sinon stub which is rendered as a child in the component under tests.

react-testing-library & Jest

Published May 28, 2018

How do you unit test your React components? There are plenty testing libraries to help support testing your React app. I’m going to look at using Jest and Kent C. Dodds @testing-library/react

Recycle tests in TDD and code kata

Published Feb 12, 2018

Have you ever written a unit test and it seems to take a long time to make green?

What is a long time, you might ask? In my opinion if you spend more than 5 minutes solving the test you wrote then you are in the amber zone that you made it too complex. If greater than 10 minutes then you need to simplify the test. Which might not seem like an obvious thing to do.

This exercise is to help unblock the solving of complex tests consistently and quicker.

Stubbing Reflux and SuperAgent with Sinon

Published Mar 6, 2016

To follow on from the testing post I wrote on Findmypast tech blog for stubbing dependances in commonJS using proxyquire.