Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocked Date objects break module #22

Closed
nijk opened this issue Sep 23, 2019 · 1 comment
Closed

Mocked Date objects break module #22

nijk opened this issue Sep 23, 2019 · 1 comment

Comments

@nijk
Copy link

nijk commented Sep 23, 2019

When using this module in a project tested with cypress.io and using the date mock method cy.clock() the function getDateAndTimeBeingFormatted throws this error: Unsupported relative time formatter input.

I believe this is because the check for a valid date is done using this expression.

In my case the constructor is not the Date object but rather one determined by lolex which Cypress uses under the hood. From my research on this subject, it seems appropriate to test the date in a manner similar to this popular SO post on the subject

@catamphetamine
Copy link
Owner

Hi.
I see.
I simplified it to just:

// During testing via some testing libraries `Date`s aren't actually `Date`s.
// https://github.com/catamphetamine/javascript-time-ago/issues/22
function isMockedDate(object) {
	return typeof object === 'object' && typeof object.getTime === 'function'
}

Released javascript-time-ago@2.0.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants