Skip to content

Commit

Permalink
🦐 Jest to mocha migration guide (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
yivlad committed Mar 25, 2022
1 parent bf0a18e commit 4cd1574
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 6 deletions.
52 changes: 51 additions & 1 deletion docs/source/migration-guides.rst
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ so we decided not to use this field. Now we support just :code:`contract.abi`.
Migration from Waffle 3.4.0 to Waffle 4.0.0-alpha
-----------------------------------------------
-------------------------------------------------

Dependencies upgrades
~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -319,3 +319,53 @@ If you used type generation (:code:`typechainEnabled` option set to :code:`true`
const contractConstructorArgs: [string, string] = [bob.address, charlie.address];
-const contract = await deployContract(alice, MyContractFactory, contractConstructorArgs);
+const contract = await deployContract(alice, MyContract__factory, contractConstructorArgs);
:code:`@ethereum-waffle/jest` deprecated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We stopped supporting :code:`@ethereum-waffle/jest`. From now on the package is deprecated and will be removed in the future. The suggested test framework to use with :code:`Waffle` is :code:`mocha` combined with :code:`chai` and :code:`@ethereum-waffle/chai` package. If you want to migrate from `jest` to `mocha` in your project, please follow the guide below.

1. Setup :code:`mocha` - this may include the following steps:

- installing :code:`mocha` and :code:`chai` packages.
- if you are using :code:`typescript`, installing :code:`@types/mocha`, :code:`@types/chai` and :code:`ts-node` packages.
- updating your :code:`test` script (the common pattern for typescript is :code:`"test": "mocha -r ts-node/register/transpile-only 'test/**/*.test.ts'"`).
- updating your tests to use :code:`mocha` syntax.

2. Replace :code:`@ethereum-waffle/jest` with :code:`@ethereum-waffle/chai`. Below is little table that contains the list of all the matchers provided by :code:`@ethereum-waffle/jest` and their replacements in :code:`@ethereum-waffle/chai`.

.. list-table:: Matchers replacements
:widths: 50 50
:header-rows: 1

* - @ethereum-waffle/jest
- @ethereum-waffle/chai
* - :code:`.toChangeBalance(wallet, balanceChange)`
- :code:`.to.changeEtherBalance(wallet, balanceChange)`
* - :code:`.toChangeBalances(wallets, balanceChanges)`
- :code:`.to.changeEtherBalances(wallets, balanceChanges)`
* - :code:`.toBeGtBN(value)`
- :code:`.to.be.gt(value)`
* - :code:`.toBeLtBN(value)`
- :code:`.to.be.lt(value)`
* - :code:`.toBeGteBN(value)`
- :code:`.to.be.gte(value)`
* - :code:`.toBeLteBN(value)`
- :code:`.to.be.lte(value)`
* - :code:`.toEqBN(value)`
- :code:`.to.equal(value)`
* - :code:`.toHaveEmitted(contract, eventName)`
- :code:`.to.emit(contract, eventName)`
* - :code:`.toHaveEmittedWith(contract, eventName, args)`
- :code:`.to.emit(contract, eventName).withArgs(...args)`
* - :code:`.toThrowErrorMatchingSnapshot()`
- :code:`.to.be.eventually.rejectedWith(expected, message)`
* - :code:`.toBeProperPrivateKey()`
- :code:`.to.be.properPrivateKey`
* - :code:`.toBeProperAddress()`
- :code:`.to.be.properAddress`
* - :code:`.toBeReverted()`
- :code:`.to.be.reverted`
* - :code:`.toBeRevertedWith(revertReason)`
- :code:`.to.be.revertedWith(reason)`

2 changes: 1 addition & 1 deletion waffle-chai/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![CircleCI](https://circleci.com/gh/EthWorks/Waffle.svg?style=svg)](https://circleci.com/gh/EthWorks/Waffle)
![CI](https://github.com/EthWorks/Waffle/workflows/CI/badge.svg)
[![](https://img.shields.io/npm/v/@ethereum-waffle/chai.svg)](https://www.npmjs.com/package/@ethereum-waffle/chai)

![Ethereum Waffle](https://raw.githubusercontent.com/EthWorks/Waffle/master/docs/source/logo.png)
Expand Down
2 changes: 1 addition & 1 deletion waffle-compiler/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![CircleCI](https://circleci.com/gh/EthWorks/Waffle.svg?style=svg)](https://circleci.com/gh/EthWorks/Waffle)
![CI](https://github.com/EthWorks/Waffle/workflows/CI/badge.svg)
[![](https://img.shields.io/npm/v/@ethereum-waffle/compiler.svg)](https://www.npmjs.com/package/@ethereum-waffle/compiler)

![Ethereum Waffle](https://raw.githubusercontent.com/EthWorks/Waffle/master/docs/source/logo.png)
Expand Down
2 changes: 1 addition & 1 deletion waffle-ens/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![CircleCI](https://circleci.com/gh/EthWorks/Waffle.svg?style=svg)](https://circleci.com/gh/EthWorks/Waffle)
![CI](https://github.com/EthWorks/Waffle/workflows/CI/badge.svg)
[![](https://img.shields.io/npm/v/@ethereum-waffle/ens.svg)](https://www.npmjs.com/package/@ethereum-waffle/ens)

![Ethereum Waffle](https://raw.githubusercontent.com/EthWorks/Waffle/master/docs/source/logo.png)
Expand Down
8 changes: 8 additions & 0 deletions waffle-jest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
![CI](https://github.com/EthWorks/Waffle/workflows/CI/badge.svg)
[![](https://img.shields.io/npm/v/@ethereum-waffle/chai.svg)](https://www.npmjs.com/package/@ethereum-waffle/chai)

![Ethereum Waffle](https://raw.githubusercontent.com/EthWorks/Waffle/master/docs/source/logo.png)

# @ethereum-waffle/jest

The package is deprecated. Please consider using [@ethereum-waffle/chai](https://www.npmjs.com/package/@ethereum-waffle/chai).
2 changes: 1 addition & 1 deletion waffle-mock-contract/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Ethereum Waffle](https://raw.githubusercontent.com/EthWorks/Waffle/master/docs/source/logo.png)

[![CircleCI](https://circleci.com/gh/EthWorks/Waffle.svg?style=svg)](https://circleci.com/gh/EthWorks/Waffle)
![CI](https://github.com/EthWorks/Waffle/workflows/CI/badge.svg)
[![](https://img.shields.io/npm/v/@ethereum-waffle/mock-contract.svg)](https://www.npmjs.com/package/@ethereum-waffle/mock-contract)

# @ethereum-waffle/mock-contract
Expand Down
2 changes: 1 addition & 1 deletion waffle-provider/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Main CI](https://github.com/TrueFiEng/Waffle/actions/workflows/CI.yml/badge.svg)](https://github.com/TrueFiEng/Waffle/actions/workflows/CI.yml)
![CI](https://github.com/EthWorks/Waffle/workflows/CI/badge.svg)
[![](https://img.shields.io/npm/v/@ethereum-waffle/provider.svg)](https://www.npmjs.com/package/@ethereum-waffle/provider)

![Ethereum Waffle](https://raw.githubusercontent.com/EthWorks/Waffle/master/docs/source/logo.png)
Expand Down

0 comments on commit 4cd1574

Please sign in to comment.