Skip to content

Commit

Permalink
0.11.1: use global in jest context
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed Jun 17, 2021
1 parent 958e1e7 commit be3e446
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 11 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,5 @@ npm publish

#### Jest

In your jest test environment `global` is `window`, so in order to have your implementation still rely on `window` (e.g. `window.ethereum`) pass `global` as `window` to `Web3Mock`:

```javascript
Web3Mock({ window: global, mocks: 'ethereum' });
```
In your jest test environment `global` is `window`
so `Web3Mock` takes jest's `global` automatically when using `Web3Mock` in a jest test environment.
6 changes: 5 additions & 1 deletion dist/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,11 @@ let mock = function ({ configuration, window, provider }) {
}
};

let Web3Mock = ({ mocks, provider, window = window }) => {
let Web3Mock = ({
mocks,
provider,
window = typeof window == 'object' ? window : typeof global == 'object' ? global : undefined,
}) => {
if (mocks === undefined || mocks.length === 0) {
throw 'Web3Mock: No mocks defined!'
}
Expand Down
6 changes: 5 additions & 1 deletion dist/es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ let mock = function ({ configuration, window, provider }) {
}
};

let Web3Mock = ({ mocks, provider, window = window }) => {
let Web3Mock = ({
mocks,
provider,
window = typeof window == 'object' ? window : typeof global == 'object' ? global : undefined,
}) => {
if (mocks === undefined || mocks.length === 0) {
throw 'Web3Mock: No mocks defined!'
}
Expand Down
6 changes: 5 additions & 1 deletion dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,11 @@
}
};

let Web3Mock = ({ mocks, provider, window = window }) => {
let Web3Mock = ({
mocks,
provider,
window = typeof window == 'object' ? window : typeof global == 'object' ? global : undefined,
}) => {
if (mocks === undefined || mocks.length === 0) {
throw 'Web3Mock: No mocks defined!'
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "depay-web3mock",
"moduleName": "Web3Mock",
"version": "0.11.0",
"version": "0.11.1",
"description": "JavaScript library to mock web3 responses either by emulating blockchain wallets or RPC calls.",
"main": "./dist/cjs/index.js",
"files": [
Expand Down
6 changes: 5 additions & 1 deletion src/Web3Mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ let mock = function ({ configuration, window, provider }) {
}
}

let Web3Mock = ({ mocks, provider, window = window }) => {
let Web3Mock = ({
mocks,
provider,
window = typeof window == 'object' ? window : typeof global == 'object' ? global : undefined,
}) => {
if (mocks === undefined || mocks.length === 0) {
throw 'Web3Mock: No mocks defined!'
}
Expand Down
7 changes: 6 additions & 1 deletion tests/units/web3mock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ describe('Web3Mock', () => {

});


it('does not change existing values in the passed window object', () => {

let window = { someVar: 1, ethereum: { existedAlready: 1 } }
Expand Down Expand Up @@ -56,4 +55,10 @@ describe('Web3Mock', () => {
}).toThrow('Web3Mock: Unknown blockchain!');

});

it('takes jest "global" automatically if there is no window but a global', () => {

Web3Mock({ mocks: ['ethereum'] });

});
});

0 comments on commit be3e446

Please sign in to comment.