我正在使用this question作为我当前代码的基础。我基本上试图测试的是确保正确的调用。我目前的D3功能如下:
public updateDrawnData() {
d3.selectAll('.linePaths')
.transition()
.duration(1000)
.attr('d', (d) => {
return this.line(d.data);
});
}
我目前的测试如下:
import { D3LineClass } from './line-class'
import * as d3 from 'd3';
describe('D3 Line Class', () => {
const testD3Class = new D3LineClass();
it('should select and upate the drawn lines', () => {
let d3SpyObject = jasmine.createSpyObj(d3, ['transition', 'duration', 'attr']);
spyOn(d3, 'selectAll').and.returnValue(d3SpyObject);
d3SpyObject.attr.and.callFake((key, value) => {
return this;
});
testD3Class.updateDrawnData();
expect(d3.selectAll).toHaveBeenCalledWith('.linePaths');
expect(d3SpyObject.transition).toHaveBeenCalled();
expect(d3SpyObject.duration).toHaveBeenCalledWith(1000);
expect(d3SpyObject.attr).toHaveBeenCalled();
})
});
但我一直收到以下错误:
TypeError: Cannot read property 'duration' of undefined
我仍然是Jasmine的新手,我无法弄清楚为什么会出现这个错误。