fastcodejava
fastcodejava

Reputation: 41097

Error adding a test case to an angular app in stackblitz

My angular app does not work on stackblitz when I added a test case. I'm getting this weird error: Import error, can't find file: ./test-files.ts. It worked fine before adding the test.

Upvotes: 0

Views: 201

Answers (2)

Lia
Lia

Reputation: 11982

first you should install:

jasmine-core
@types/jasmine

then add a jasmine-setup to your project:

import jasmineRequire from 'jasmine-core/lib/jasmine-core/jasmine.js';
window.jasmineRequire = jasmineRequire;

and in typings.d:

interface Window {
  jasmineRequire: any;
  jasmineRef: any;
}

declare module 'jasmine-core/lib/jasmine-core/jasmine.js' {}

and in your main.ts:

let TEST = true;

if (TEST) {
  (function bootstrap () {
    if (window.jasmineRef) {
      location.reload();

      return;
    }

    window.onload(new Event('anything'));
    window.jasmineRef = jasmine.getEnv();
  }());
}

this Stackblitz example can help you.

Upvotes: 1

Amith Dissanayaka
Amith Dissanayaka

Reputation: 1059

You added your test-files in outside of the src. Add it inside the src.

Or Change the main.ts import as '../test-files.ts'

Upvotes: 0

Related Questions