Topic: Unit-Test errors: SyntaxError: Unexpected token export

Daniel Sogl pro asked 6 years ago


I upgraded my project from the PRO version downloaded as *zip folder to an installation with npm and my received gitlab account. Now I have problems with my unit-tests in components with mdbootstrap directives like modals.

If I run my tests I receive this errors:

C:UsersmytecProjektedhbw-projekt-2017node_modulesng-mdb-proindex.ts:1

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export {MDBBootstrapModules} from './mdb.module';

SyntaxError: Unexpected token export

at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:305:17)
at Object.<anonymous> (src/app/pages/dashboard-page/dashboard-page.component.spec.ts:11:20)
at Generator.next (<anonymous>)

This is my app.component.ts

import { Component, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { MDBSpinningPreloader } from 'ng-mdb-pro';

@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss']

})

export class AppComponent implements OnInit {

constructor(private mdbSpinningPreloader: MDBSpinningPreloader, translate: TranslateService) {
// Configure ngx-translate
translate.setDefaultLang('de');
translate.use(translate.getBrowserLang());
}

ngOnInit() {
this.mdbSpinningPreloader.stop();
}

}

This is my app.component.spec.ts

import { NO_ERRORS_SCHEMA } from '@angular/core';
import { async, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
import { AngularFireModule } from 'angularfire2';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFirestore, AngularFirestoreModule } from 'angularfire2/firestore';
import { MDBBootstrapModules, MDBSpinningPreloader } from 'ng-mdb-pro';

import { FakeLoader } from '../../jest-mocks/fake-loader';
import { environment } from '../environments/environment';
import { AppComponent } from './app.component';
import { FooterComponent } from './components/footer/footer.component';
import { NavigationBarComponent } from './components/navigation-bar/navigation-bar.component';
import { FirebaseAuthService } from './services/auth/firebase-auth/firebase-auth.service';

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
MDBBootstrapModules.forRoot(),
AngularFireModule.initializeApp(environment.firebase),
TranslateModule.forRoot({
loader: {provide: TranslateLoader, useClass: FakeLoader},
})
],
declarations: [
AppComponent,
NavigationBarComponent,
FooterComponent
],
providers: [
FirebaseAuthService,
AngularFireAuth,
TranslateService,
MDBSpinningPreloader,
{ provide: AngularFirestore, depends: AngularFirestoreModule }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));

it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));

});

If I check the mdb.module.ts file inside the ng-mdb-pro folder I can see some reference errors with the MDBBootstrapModulePro exports from the pro folder.
Maybe you can fix that exports for me with the latest patch release.

Kind regards,

Daniel


Dawid Adach pro answered 6 years ago


Dear Daniel, this looks like version mismatch issue. Of course  "export" is a valid syntax, however, most probably some issues which occur during compilation are causing a domino effect which at points to the different place from where the root cause lays. Please try to create an empty project with the fresh installation.

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags