0

I have a project that was on jasmine, and I'm trying to migrate to jest. All I changed was the jasmine.createSpy to jest.fn, so I suspect it's something with my configuration.

Here is my old spec.ts file with jasmine:

    myServiceMock= {
      mockFunction: jasmine.cresateSpy('mockFunction')
    };
    TestBed.configureTestingModule({
      declarations: [SomeComponent],
      providers: [
        { provide: MyService, useValue: MySericeMock}
      ]
    }).compileComponents()

and now with jest:

    myServiceMock= {
      mockFunction: jest.fn() // <-- The only thing that I changed in this file
    };
    TestBed.configureTestingModule({
      declarations: [SomeComponent],
      providers: [
        { provide: MyService, useValue: MySericeMock}
      ]
    }).compileComponents()

This is my tsconfig.spec.json:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "../../dist/out-tsc",
    "types": ["jest", "node"],
    "emitDecoratorMetadata": true
  },
  "files": ["src/test-setup.ts"],
  "include": ["**/*.spec.ts", "**/*.d.ts"]
}

The test.setup.ts file only has an import : import 'jest-preset-angular';

And this is the error I'm getting: 'Cannot read property 'injector' of null'

What am I missing?

Felipe Centeno
  • 2,911
  • 1
  • 21
  • 39

0 Answers0