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

Expand on our Timestamp mock #39

Merged
merged 17 commits into from
Sep 28, 2020
Merged

Expand on our Timestamp mock #39

merged 17 commits into from
Sep 28, 2020

Conversation

AverageHelper
Copy link
Contributor

Description

Our mocked Firebase.Timestamp class now covers Firestore's API for toDate, toMillis getters, and fromDate and fromMillis constructors.

The corresponding Jest mock functions may be used to inject return values to these functions, like so:

// ... import firebase, mockTimestampToMillis ...

mockTimestampToMillis.mockReturnValue(400);
console.log(new firebase.firestore.Timestamp().toMillis()); // prints '400'

Related issues

Depends on #38

How to test

jest

This was referenced Aug 4, 2020
@AverageHelper AverageHelper marked this pull request as ready for review September 18, 2020 22:28
@FrozenKiwi
Copy link
Contributor

I'm not sure if this change is inlcuded in this changelist (or if it listed somewhere else) but there is an issue in the timestamp implementation:

  static fromDate(date) {
    return (
      mockTimestampFromDate(...arguments) ||
      new Timestamp(date.getSeconds(), date.getMilliseconds() * 1000000)
    );
  }

note date.getSeconds returns only the number of seconds since the last minute, not the full number of seconds since epoch.

A suggested change here: thecointech@9bc4d4a

(or I can add this as a PR once the subCollections PR has been merged)

@AverageHelper
Copy link
Contributor Author

That's a good point @FrozenKiwi. I believe date.getTime returns the time since reference in milliseconds, right? I'll put up a commit with that instead.

Copy link
Owner

@sbatson5 sbatson5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! 🙌 Just a couple of comments

__tests__/transaction.test.js Outdated Show resolved Hide resolved
__tests__/transaction.test.js Show resolved Hide resolved
__tests__/transaction.test.js Outdated Show resolved Hide resolved
__tests__/transaction.test.js Show resolved Hide resolved
mocks/firestore.js Show resolved Hide resolved
mocks/helpers/buildDocFromHash.js Outdated Show resolved Hide resolved
mocks/helpers/buildDocFromHash.js Show resolved Hide resolved
Copy link
Owner

@sbatson5 sbatson5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Nice work 🙌

@sbatson5 sbatson5 merged commit e39a038 into sbatson5:master Sep 28, 2020
@AverageHelper AverageHelper deleted the pr-4 branch September 28, 2020 20:41
@AverageHelper
Copy link
Contributor Author

Thanks! #40 is ready for review.

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 this pull request may close these issues.

3 participants