jest-mock-random
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -33,5 +33,7 @@ const { | ||
it('throw Error in case we pass an empty array', () => { | ||
const actual = () => Math.random(); | ||
expect(actual).toThrow(TypeError); | ||
try { | ||
Math.random(); | ||
} catch (e) { | ||
expect(e).not.toBeNull(); | ||
} | ||
}); | ||
@@ -38,0 +40,0 @@ }); |
@@ -0,0 +0,0 @@ module.exports = { |
{ | ||
"name": "jest-mock-random", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Math.random() as a deterministic jest mock function", | ||
@@ -17,3 +17,3 @@ "main": "index.js", | ||
"precommit": "lint-staged", | ||
"test": "jest **.js", | ||
"test": "jest **/*.js", | ||
"test-watch": "jest --watch", | ||
@@ -35,12 +35,10 @@ "lint": "eslint \"index.js\" \"__tests__/**/*.js\"" | ||
"devDependencies": { | ||
"eslint": "^4.15.0", | ||
"eslint-config-airbnb": "^16.1.0", | ||
"eslint-plugin-import": "^2.5.0", | ||
"eslint-plugin-jsx-a11y": "^6.0.3", | ||
"eslint-plugin-react": "^7.5.1", | ||
"husky": "^0.14.1", | ||
"jest": "^22.1.1", | ||
"jest-cli": "^22.0.4", | ||
"lint-staged": "^6.0.0" | ||
"eslint": "^6.6.0", | ||
"eslint-config-airbnb": "^18.0.1", | ||
"eslint-plugin-import": "^2.18.2", | ||
"husky": "^3.1.0", | ||
"jest": "^24.9.0", | ||
"jest-cli": "^24.9.0", | ||
"lint-staged": "^9.4.3" | ||
} | ||
} |
@@ -15,9 +15,9 @@ # jest-mock-random | ||
jest-mock-random is used as an additional beforeEach for your sequence of test. | ||
jest-mock-random can be used as an additional beforeEach for your sequence of test. | ||
```javascript | ||
import mockRandomWith from 'jest-mock-random'; | ||
import { mockRandomForEach } from 'jest-mock-random'; | ||
describe('Test with random usage', () => { | ||
mockRandomWith([0.1, 0.2, 0.3, 0.6]); | ||
mockRandomForEach([0.1, 0.2, 0.3, 0.6]); | ||
it('assigns random the values that we want to mock in order', () => { | ||
@@ -34,15 +34,31 @@ const actual = [Math.random(), Math.random(), Math.random(), Math.random()]; // [0.1, 0.2, 0.3, 0.6] | ||
In the same way the mock can be use for individual test: | ||
```javascript | ||
import { mockRandom, resetMockRandom } from 'jest-mock-random'; | ||
describe('Test with random usage', () => { | ||
it('assigns random the values that we want to mock in order', () => { | ||
mockRandom([0.1, 0.2]); | ||
const actual = [Math.random(), Math.random(), Math.random(), Math.random()]; // [0.1, 0.2, 0.1, 0.2] | ||
expect(actual).toEqual([0.1, 0.2, 0.1, 0.2]); | ||
resetMockRandom(); | ||
}); | ||
}); | ||
``` | ||
WARNING: if a no decimal value is passed it will print some warnings during the test. | ||
```javascript | ||
mockRandomWith([0.1, 0.2]); // OK | ||
mockRandomWith([0.1, '0.2']); // OK | ||
mockRandomWith(['0.2', '0.2']); // OK | ||
mockRandomWith(0.2); // OK | ||
mockRandomWith('0.2'); // OK | ||
mockRandomForEach([0.1, 0.2]); // OK | ||
mockRandomForEach([0.1, '0.2']); // OK | ||
mockRandomForEach(['0.2', '0.2']); // OK | ||
mockRandomForEach(0.2); // OK | ||
mockRandomForEach('0.2'); // OK | ||
mockRandomWith('a'); // WARNING | ||
mockRandomWith(13); // WARNING | ||
mockRandomWith({}); // WARNING | ||
mockRandomWith([]); // WARNING | ||
mockRandomWith(['a', 1]); // WARNING | ||
mockRandomForEach('a'); // WARNING | ||
mockRandomForEach(13); // WARNING | ||
mockRandomForEach({}); // WARNING | ||
mockRandomForEach([]); // WARNING | ||
mockRandomForEach(['a', 1]); // WARNING |
Sorry, the diff of this file is not supported yet
7
11
178
63
12199