All Projects → HugoDF → jest-mock-date-examples

HugoDF / jest-mock-date-examples

Licence: MIT License
Different approaches to mocking the Date in Jest tests

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to jest-mock-date-examples

jest-wrap
Fluent pluggable interface for easily wrapping `describe` and `it` blocks in Jest tests.
Stars: ✭ 35 (+59.09%)
Mutual labels:  jest, jest-tests
jest-handbook-examples
Examples for The Jest Handbook
Stars: ✭ 14 (-36.36%)
Mutual labels:  jest, jest-tests
noov.js
📦 noov.js for react ssr solution
Stars: ✭ 18 (-18.18%)
Mutual labels:  jest, jest-tests
awesome-address-book
This project shows a basic address book built with ReactJS, Redux Toolkit and Typescript 📖
Stars: ✭ 20 (-9.09%)
Mutual labels:  jest
reducer-tester
Utilities for testing redux reducers
Stars: ✭ 19 (-13.64%)
Mutual labels:  jest
puppeteer-screenshot-tester
Small library that allows us to compare screenshots generated by puppeteer in our tests.
Stars: ✭ 50 (+127.27%)
Mutual labels:  jest
react-boilerplate
Sets the ground up for CRA-like projects.
Stars: ✭ 23 (+4.55%)
Mutual labels:  jest
personal-blog
✍️ 个人技术博客
Stars: ✭ 79 (+259.09%)
Mutual labels:  jest
art-ui
🌈 A UI Design Language and React UI library
Stars: ✭ 34 (+54.55%)
Mutual labels:  jest
egghead-bookshelf
An example React application to accompany the "Add Internationalization (i18n) to a React app using React Intl" Egghead.io course
Stars: ✭ 28 (+27.27%)
Mutual labels:  jest
awesome-javascript-testing
🔧 Awesome JavaScript testing resources
Stars: ✭ 28 (+27.27%)
Mutual labels:  jest
jest-preset-preact
Jest preset for testing Preact apps
Stars: ✭ 14 (-36.36%)
Mutual labels:  jest
GFontsSpace
Preview: https://pankajladhar.github.io/GFontsSpace
Stars: ✭ 88 (+300%)
Mutual labels:  jest
core
The XP Framework is an all-purpose, object oriented PHP framework.
Stars: ✭ 13 (-40.91%)
Mutual labels:  date-time
automock
A library for testing classes with auto mocking capabilities using jest-mock-extended
Stars: ✭ 26 (+18.18%)
Mutual labels:  jest
mocking-with-jest
API Testing with Jest
Stars: ✭ 41 (+86.36%)
Mutual labels:  jest-tests
jest-dashboard
Command Line Dashboard for Jest
Stars: ✭ 61 (+177.27%)
Mutual labels:  jest
Fable.Jester
Fable bindings for jest and friends for delightful Fable testing.
Stars: ✭ 28 (+27.27%)
Mutual labels:  jest
gradle-upgrade-interactive
CLI to interactively upgrade gradle dependencies, inspired by yarn.
Stars: ✭ 44 (+100%)
Mutual labels:  jest
nuxt-boilerplate
Nuxt.js Boilerplate
Stars: ✭ 25 (+13.64%)
Mutual labels:  jest

Jest Mock Date examples

Different approaches to mocking the Date in Jest tests

See the full post and explanation at codewithhugo.com/mocking-the-current-date-in-jest-tests.

There are 2 general approaches to mocking the current date:

  • Using new Date() and mocking the constructor.
  • Using new Date(Date.now()) and mocking the output of Date.now().

For each of those approaches in the application code, this repo has examples for a spy-based approach and a full function/constructor stub/mock replacement:

Running the tests

Packages were installed with yarn, although npm should work just as well.

  • Run yarn
  • Run yarn test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].