Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using firestore.Timestamp.now() in Angular unit test

I am developing an Angular application, with angularfire2 5.0.0-rc.10. I really hope I don't mess up any terms in the following, but here we go.

I have converted Date's, to the new firestore Timestamp type. This gives me a problem when writing tests. I can only do the following:

import { firestore } from 'firebase/app';
it ('should create', () => {
   firestore.Timestamp.now();
});

If I initialize firebase in my TestBed module with:

AngularFireModule.initializeApp(environment.firebase),

Otherwise I get the error:

TypeError: Cannot read property 'Timestamp' of undefined

So my questions:

  1. Is this intended behaviour?
  2. Are you not supposed to be able to create a firstore Timestamp data type, outside of an firebase angular project?
  3. Why is firestore undefined when imported without the initializeApp?

Thanks so much for your help.

like image 873
DauleDK Avatar asked May 29 '18 10:05

DauleDK


1 Answers

I resolved it below

angular version is 11.1.2

import firebase from 'firebase/app';
import 'firebase/firestore';
import Timestamp = firebase.firestore.Timestamp;
like image 183
倉田隆成 Avatar answered Nov 08 '22 21:11

倉田隆成