SB-Admin-BS4-Angular-8 icon indicating copy to clipboard operation
SB-Admin-BS4-Angular-8 copied to clipboard

No enable to run unit test with karma

Open hmendezm opened this issue 6 years ago • 6 comments

Hi Guys,

first at all, great job. I was able to run the application. I am trying to run unit test but I get the error below. Do you any idea how to fix this?

Chrome 60.0.3112 (Windows 7 0.0.0) ERROR Uncaught Error: Missing: SyncTestZoneSpec at http://localhost:9876/karma_webpack/vendor.bundle.js:42339

Chrome 60.0.3112 (Windows 7 0.0.0) ERROR Uncaught Error: Missing: SyncTestZoneSpec at http://localhost:9876/karma_webpack/vendor.bundle.js:42339

Best regards hmendezm

hmendezm avatar Aug 03 '17 20:08 hmendezm

Hi,

FYI, test ran by modifying the test.ts : import 'zone.js/dist/long-stack-trace-zone'; import 'zone.js/dist/proxy'; import 'zone.js/dist/sync-test'; import 'zone.js/dist/jasmine-patch'; import 'zone.js/dist/async-test'; import 'zone.js/dist/fake-async-test';

https://github.com/start-angular/SB-Admin-BS4-Angular-4/issues/126

Dorian-s avatar Aug 28 '17 17:08 Dorian-s

@Dorian-s seems that doesn't work. `HeadlessChrome 0.0.0 (Windows 7 0.0.0) ERROR Uncaught Error: Missing: SyncTestZoneSpec at http://localhost:9876/karma_webpack/vendor.bundle.js:43997 HeadlessChrome 0.0.0 (Windows 7 0.0.0) ERROR Uncaught Error: Missing: SyncTestZoneSpec at http://localhost:9876/karma_webpack/vendor.bundle.js:43997

HeadlessChrome 0.0.0 (Windows 7 0.0.0) ERROR Uncaught Error: Missing: SyncTestZoneSpec at http://localhost:9876/karma_webpack/vendor.bundle.js:43997 `

HackPoint avatar Oct 14 '17 20:10 HackPoint

I just changed the imports to:

import 'zone.js/dist/zone.js'; import 'zone.js/dist/async-test'; import 'zone.js/dist/fake-async-test'; import 'zone.js/dist/long-stack-trace-zone'; import 'zone.js/dist/proxy.js'; import 'zone.js/dist/sync-test'; import 'zone.js/dist/jasmine-patch';

and it worked for me

Giusti avatar Oct 14 '17 23:10 Giusti

but it seems i am getting the following error now

TypeError: Cannot read property 'assertPresent' of undefined
            at resetFakeAsyncZone C:/Users/Giusti/Projects/testapp/node_modules/@angular/core/@angular/core/testing.es5.js:308:1)
            at Object.<anonymous> C:/Users/Giusti/Projects/testapp/node_modules/@angular/core/@angular/core/testing.es5.js:1015:1)
            at ZoneQueueRunner.webpackJsonp.../../../../zone.js/dist/jasmine-patch.js.jasmine.QueueRunner.ZoneQueueRunner.execute C:/Users/Giusti/Projects/testapp/node_modules/zone.js/dist/jasmine-patch.js:
132:1)

for basically all my tests

Giusti avatar Oct 15 '17 08:10 Giusti

Is there any solution for this??? I ran into the same problem

p4pramod avatar Nov 03 '17 10:11 p4pramod

i changed my test.ts file as bellow :

`// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import 'zone.js/dist/long-stack-trace-zone'; import 'zone.js/dist/proxy.js'; import 'zone.js/dist/sync-test'; import 'zone.js/dist/jasmine-patch'; import 'zone.js/dist/async-test'; import 'zone.js/dist/fake-async-test'; import { getTestBed } from '@angular/core/testing'; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';

// Unfortunately there's no typing for the __karma__ variable. Just declare it as any. declare const karma: any; declare const require: any;

// Prevent Karma from running prematurely. karma.loaded = function () {};

// First, initialize the Angular testing environment. getTestBed().initTestEnvironment( BrowserDynamicTestingModule, platformBrowserDynamicTesting() ); // Then we find all the tests. const context = require.context('./', true, /.spec.ts$/); // And load the modules. context.keys().map(context); // Finally, start Karma to run the tests. karma.start(); `

I was getting it by creating a new project and then copy paste the test.ts file

boubakar-zeineb avatar Nov 04 '17 23:11 boubakar-zeineb