Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-mock-promise

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-mock-promise - npm Package Compare versions

Comparing version 1.0.18 to 1.0.19

2

package.json
{
"name": "jest-mock-promise",
"version": "1.0.18",
"version": "1.0.19",
"description": "Synchronous Promise Mock for testing with Jest",

@@ -5,0 +5,0 @@ "main": "dist/jest-mock-promise.js",

@@ -20,3 +20,3 @@ # What's this?

Well' it works the same way a normal Promise would work, with the exception that does it right away and not at later time.
It works the same way a normal Promise would, with the exception that does it right away (synchronously) and not at later time (async).

@@ -66,5 +66,9 @@ Let's use the following example to see how a synchronous promise is different from a regular one:

Synchronous Promise wac created to simplify unit testing an async component. So to illustrate how it can be used, in the following example we are going to test a component, which multiplies two numbers provided as a payload of a promise. The result is returned a call to a callback function.
Synchronous Promise was created to simplify unit testing an async component. So in the next two examples we'll have a look at how we can do just that - simplify a unit test.
First let's have a look a the component we want to test:
## What we'll be testing
We are going to test a component, which multiplies two numbers provided as a payload of a promise. The result is returned a call to a callback function.
The following snippet shows implementation of that component:
```javascript

@@ -82,6 +86,10 @@ // ./src/component.js

```
Now let's write a Jest tests. In our first example we'll create a test in a traditional async way ... just to show how unreadable it is. Then, in the second example, we'll simplify things by using `jest-mock-axios`.
Now let's write some Jest tests.
## First example - Traditional async test
In our first example we'll create a test in a traditional async way ... just to show how terible it is. Then, in the second example, we'll improve on the original idea by introducing `jest-mock-promise`.
The next snippet contains a test written in traditional async way:
```javascript

@@ -114,3 +122,3 @@ // ./src/__test__/component.spec.js

```
As we can see, we need to have **a hard look** at the code to see the order in which our code gets executed. Can we make this better? Yes we can! In the following section we'll see how ...
As we can see, it's not easy to see the order in which our code gets executed. Can we make this better? Yes we can! In the following section we'll see how ...

@@ -125,3 +133,3 @@ ## Second example - Applying the synchronous Promise

// mocking the es6-promise, which is used by Axios
// mocking the es6-promise, which is used by component we are testing
export { JestMockPromise as Promise };

@@ -152,3 +160,3 @@ ```

```
As we can see, there's no problem in reading this test! Hooray!
As we can see, reading our code just became much easier! Hooray!

@@ -155,0 +163,0 @@ ## Third example - Mocking Axios

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc