New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jest-mock-now

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-mock-now - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

.prettierrc

6

__tests__/index.test.js

@@ -16,2 +16,8 @@ const index = require('../');

test('init function returns the used `now` value', () => {
expect(index()).toEqual(NOW);
const now = new Date('2017-06-22');
expect(index(now)).toEqual(now.getTime());
});
test('Date.now() to match snapshot w/ options', () => {

@@ -18,0 +24,0 @@ const now = new Date('2017-06-22');

1

index.js

@@ -6,2 +6,3 @@ const { NOW } = require('./constants');

Date.now = jest.spyOn(Date, 'now').mockImplementation(() => now);
return now;
};

26

package.json
{
"name": "jest-mock-now",
"version": "1.1.1",
"version": "1.2.0",
"description": "Date.now() as deterministic Jest mock function.",

@@ -28,3 +28,4 @@ "main": "index.js",

"name": "Mattia Richetto",
"email": "mattia.richetto@gmail.com"
"email": "mattia.richetto@gmail.com",
"url": "https://mattiaerre.github.io/"
},

@@ -37,11 +38,11 @@ "license": "MIT",

"devDependencies": {
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint": "^4.15.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.5.0",
"eslint-plugin-jsx-a11y": "^5.0.3",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-prettier": "^2.1.2",
"eslint-plugin-react": "^7.1.0",
"husky": "^0.14.1",
"jest": "^20.0.4",
"lint-staged": "^4.0.0",
"jest-cli": "^22.0.4",
"lint-staged": "^6.0.0",
"prettier": "^1.4.4"

@@ -53,3 +54,10 @@ },

]
}
}
},
"contributors": [
{
"name": "danigb",
"email": "danigb@gmail.com",
"url": "https://github.com/danigb"
}
]
}

@@ -16,3 +16,3 @@ # jest-mock-now

```javascript
require('jest-mock-now')();
const timestamp = require('jest-mock-now')();

@@ -27,5 +27,12 @@ console.log(Date.now()); // 1479427200000

require('jest-mock-now')(now);
console.log(Date.now()); // 149808960000
```
console.log(Date.now()); // 1498089600000
The `jest-mock-now` function returns the timestamp used to mock the `Date.now` method:
```javascript
const timestamp = require('jest-mock-now')(new Date('2017-06-22'));
console.log(timestamp); // 1498089600000
console.log(Date.now()); // 149808960000
```

@@ -32,0 +39,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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