Brian Stanley
Brian Stanley

Reputation: 2196

Basic create component test failing with MoJs

I have a component that is using the animation library Mojs. The create component test that comes out of the box with the spec.ts file is failing because of MoJs elements. I am not sure how to provide this library in the spec.ts file so that at the least this test for the component successfully creating passes.

The error I am getting is: 'Cannot read property 'CustomShape' of undefined'

the implementation of this CustomShape looks like:

    class paperOutlineTopCorner3 extends mojs.CustomShape {
     getShape () { return '<path d="123XYZ"/>'; }
    }

my current spec.ts file:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { CallbackComponent } from './callback.component';
import { requiredTestModules } from '../testing/import.helpers';

describe('CallbackComponent', () => {
 let component: CallbackComponent;
 let fixture: ComponentFixture<CallbackComponent>;

beforeEach(async(() => {
 TestBed.configureTestingModule({
  declarations: [ CallbackComponent ],
  imports: [requiredTestModules]
})
.compileComponents();
}));

beforeEach(() => {
 fixture = TestBed.createComponent(CallbackComponent);
 component = fixture.componentInstance;
 fixture.detectChanges();
});

it('should create', () => {
 expect(component).toBeTruthy();
});
});

any help/suggestions would be much appreciated

Upvotes: 2

Views: 128

Answers (1)

JBoothUA
JBoothUA

Reputation: 3149

First you'll have to have your mojs object defined. Hopefully there is a library you can install into your node_modules folder? After you have the mojs definitions in the node_modules folder you can import it into the file and as long as mojs.CustomShape is defined in that import you should be good to go.

you might be able to do something like

npm install mojs

and then to import it, you can try a couple of different things:

i'd try require:

const mojs = require('mojs');

or import:

import * as mojs from 'mojs';

it's even easier if the mojs library has been 'typed' already.

also can you build correctly? but only get the error when testing? that's usually an indication that something from your .module file needs to be copied into the .spec file.

hope that helps

Upvotes: 2

Related Questions