我设置了一个简单的角度CLI回购来演示我的问题,https://github.com/hummorsa/angular-cli-lodash-test/
基本上在这个测试中:
it('should sort Users', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
fixture.componentInstance.transform();
expect(fixture.componentInstance.users[0].age).toEqual(34);(});
我在运行测试时会发现错误,
TypeError:无法读取未定义的属性“sortBy”
这是代码:
public transform (): any {
this.users = _.sortBy(this.users, 'age');}
所以,基本上业力是在做测试的时候没有得到房客的参考。我尝试了一些其他答案的修正,但我无法使它发挥作用。
看起来我需要在某个地方包含这个引用,不知道在哪里/如何做它。
谢谢你的帮助。
发布于 2017-11-22 22:41:03
在继续进行研究和测试之后,我喜欢这个解决方案,并且在这次回购的最后一次提交中:https://github.com/hummorsa/angular-cli-lodash-test/,可以克隆回购并运行“ng测试”来尝试它。
基本上,提交文件的类型记录文件中的输入需要如下:
import * as _ from 'lodash'信贷:https://stackoverflow.com/a/45855755/3847132
它适合它的原因:还不清楚。
https://stackoverflow.com/questions/47440167
复制相似问题