error: No provider for @Attribute('sampleString')

拈花ヽ惹草 提交于 2019-12-02 01:26:02

The attribute needs to be

@Attribute('sampleString')

instead of

@Attribute('sampleString')

You need a test component that wraps the component that you actually want to test to be able to pass the attribute:

@component({
  selector: 'mytable', 
  templateUrl:'URL of template'
}
export class mycomp{ 
  //data members
  constructor (element ref injection, @Attribute('sampleString') private   sampleString:string){}
  //public methods
  private ngOninit(){ this.dataview = dataview of third party lib.    }
}

@component({
  selector: 'test', 
  template:'<mytable sampleString="xxx"></mytable>'
}
export class TestComponent{ 
}

//Test
describe("my test",()=>{ 
  beforeEachProviders(()=>[ mycomp, provider for elementRef]);

it('test', async(inject ([TestComponentBuilder,mycomp], (tcb: TestComponentBuilder) => {
  tcb.createAsync(TestComponent)
 .then ((fixture)=> {
    expect(true). toBe(false)
    // get the mycomp component from fixture ...
  })
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!