mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-06 12:19:08 +02:00
Do mock context properties better
This commit is contained in:
parent
c09414cc40
commit
f9a9e6bfb7
@ -97,6 +97,15 @@ describe('Point element tests', function() {
|
||||
}, {
|
||||
name: 'closePath',
|
||||
args: [],
|
||||
}, {
|
||||
name: 'setStrokeStyle',
|
||||
args: ['rgba(1, 2, 3, 1)']
|
||||
}, {
|
||||
name: 'setLineWidth',
|
||||
args: [6]
|
||||
}, {
|
||||
name: 'setFillStyle',
|
||||
args: ['rgba(0, 255, 0)']
|
||||
}, {
|
||||
name: 'fill',
|
||||
args: [],
|
||||
@ -104,10 +113,6 @@ describe('Point element tests', function() {
|
||||
name: 'stroke',
|
||||
args: []
|
||||
}]);
|
||||
|
||||
expect(mockContext.lineWidth).toBe(6);
|
||||
expect(mockContext.strokeStyle).toBe('rgba(1, 2, 3, 1)');
|
||||
expect(mockContext.fillStyle).toBe('rgba(0, 255, 0)');
|
||||
});
|
||||
|
||||
it ('should draw correctly with default settings if necessary', function() {
|
||||
@ -140,6 +145,15 @@ describe('Point element tests', function() {
|
||||
}, {
|
||||
name: 'closePath',
|
||||
args: [],
|
||||
}, {
|
||||
name: 'setStrokeStyle',
|
||||
args: ['rgba(0,0,0,0.1)']
|
||||
}, {
|
||||
name: 'setLineWidth',
|
||||
args: [1]
|
||||
}, {
|
||||
name: 'setFillStyle',
|
||||
args: ['rgba(0,0,0,0.1)']
|
||||
}, {
|
||||
name: 'fill',
|
||||
args: [],
|
||||
@ -147,10 +161,6 @@ describe('Point element tests', function() {
|
||||
name: 'stroke',
|
||||
args: []
|
||||
}]);
|
||||
|
||||
expect(mockContext.lineWidth).toBe(1);
|
||||
expect(mockContext.strokeStyle).toBe('rgba(0,0,0,0.1)');
|
||||
expect(mockContext.fillStyle).toBe('rgba(0,0,0,0.1)');
|
||||
});
|
||||
|
||||
it ('should not draw if skipped', function() {
|
||||
|
@ -3,6 +3,35 @@
|
||||
var Context = function() {
|
||||
this._calls = []; // names/args of recorded calls
|
||||
this._initMethods();
|
||||
|
||||
this._fillStyle = null;
|
||||
this._lineWidth = null;
|
||||
this._strokeStyle = null;
|
||||
|
||||
// Define properties here so that we can record each time they are set
|
||||
Object.defineProperties(this, {
|
||||
"fillStyle": {
|
||||
'get': function() { return this._fillStyle; },
|
||||
'set': function(style) {
|
||||
this._fillStyle = style;
|
||||
this.record('setFillStyle', [style]);
|
||||
}
|
||||
},
|
||||
'lineWidth': {
|
||||
'get': function() { return this._lineWidth; },
|
||||
'set': function (width) {
|
||||
this._lineWidth = width;
|
||||
this.record('setLineWidth', [width]);
|
||||
}
|
||||
},
|
||||
'strokeStyle': {
|
||||
'get': function() { return this._strokeStyle; },
|
||||
'set': function(style) {
|
||||
this._strokeStyle = style;
|
||||
this.record('setStrokeStyle', [style]);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Context.prototype._initMethods = function() {
|
||||
|
Loading…
Reference in New Issue
Block a user