moment-timezone icon indicating copy to clipboard operation
moment-timezone copied to clipboard

Question : Injecting moment-timezone to Jasmine testing.

Open danilohgds opened this issue 6 years ago • 1 comments

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 :)

danilohgds avatar Mar 22 '18 18:03 danilohgds

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

dontboyle avatar Dec 17 '18 13:12 dontboyle