Skip to content
This repository has been archived by the owner on Jan 3, 2020. It is now read-only.

Commit

Permalink
Mock global.Date
Browse files Browse the repository at this point in the history
  • Loading branch information
swinton committed Jul 18, 2018
1 parent 7a47e73 commit 050d353
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const {createRobot} = require('probot')
const app = require('..')
const payload = require('./fixtures/check_suite.requested')
const myDate = new Date(Date.UTC(2018, 0, 1))
const RealDate = Date

// Mock out the analysis implementation for these tests
// https://jestjs.io/docs/en/mock-functions#mock-implementations
Expand All @@ -13,6 +15,14 @@ describe('index', () => {
let github

beforeEach(() => {
global.Date = jest.fn(
(...props) =>
props.length
? new RealDate(...props)
: new RealDate(myDate)
)
Object.assign(Date, RealDate)

// Define event
event = {event: 'check_suite', payload: payload}

Expand All @@ -34,6 +44,10 @@ describe('index', () => {
// Pass mocked out GitHub API into out robot instance
robot.auth = () => Promise.resolve(github)
})

afterEach(() => {
global.Date = RealDate
})

it('works', async () => {
await robot.receive(event)
Expand Down

0 comments on commit 050d353

Please sign in to comment.