moment / moment-timezone

Timezone support for moment.js
momentjs.com/timezone
MIT License
3.82k stars 835 forks source link

Question : Injecting moment-timezone to Jasmine testing. #591

Open danilohgds opened 6 years ago

danilohgds commented 6 years ago

Hi folks,

Can anyone give out some clues on how to inject moment-timezone correct when testing a typescript component (Angular4)?

I get the following error in Jasmine when loading my component

"undefined is not a constructor (evaluating 'moment().tz("America/Sao_Paulo")')"

beforeEach(() => { TestBed.configureTestingModule({ imports: [AppModule, SupportModule, MomentModule] }); TestBed.compileComponents(); }); import { MomentModule } from 'angular2-moment'; import * as moment from 'moment';

If anyone here has implemented tests using the library, I am welcome to suggestions :)

dontboyle commented 5 years ago

I've been struggling with this as well for roughly a few weeks, have you made any progress?

So far i've been changing everything manually to work..

changed in actual code, not spec.ts

//return date.utc(conserveLocal);
return moment(date).utc(conserveLocal); //changed to this, jasmine couldn't find date.prototype