angular - Jasmine test for simple Angular2 component not working -


i have simple component:

@component({     selector: 'messages',     styleurls: ['messages.component.scss'],     templateurl: 'messages.component.html', }) export class messagescomponent implements oninit {      constructor(private dataservice: dataservice) {}      public getone(): number{         return 1;     } } 

i'm trying run test can't work please help:

describe('component: messagescomponent', () => {     let component: messagescomponent;      beforeeach(() => {         testbed.configuretestingmodule({             declarations: [messagescomponent],         }).compilecomponents();          const fixture = testbed.createcomponent(messagescomponent);         component = fixture.componentinstance;     });      it('should have defined component', () => {         expect(true).tobetruthy();     });  }); 

(i'm using webpack if relevant)

this error get:

    error: test module uses component messagescomponent  using "templateurl", never compiled.  please call "testbed.compilecomponents" before test. 

error: test module uses component messagescomponent using "templateurl", never compiled. please call "testbed.compilecomponents" before test.

when using webpack, shouldn't need compile components (with templateurl). templateurl's should converted inline templates when use angular2-template-loader.

see webpack.test.js example angular docs. need make sure have dependency loader. imagine should have used main project though

"devdepdendencies": {   "angular2-template-loader": "^0.4.0", } 

if you're still confused single config file linked above, might want read entire angular docs on webpack. shouldn't take long. walk through getting set both main application , tests.

also looking @ previous question, webpack config doesn't have sass support either. imagine have configured in main application webpack config. can @ see how configured. or can check this out. it's project put angular docs, reference in 1 place. angular docs doesn't add sass support, linked project add it.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -