]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Do mock context properties better
authorEvert Timberg <evert.timberg@gmail.com>
Sat, 29 Aug 2015 03:20:01 +0000 (23:20 -0400)
committerEvert Timberg <evert.timberg@gmail.com>
Sat, 29 Aug 2015 03:20:01 +0000 (23:20 -0400)
test/element.point.tests.js
test/mockContext.js

index e20964422e7caeea2ceb3d9e76da46e9327f8f20..8a4052ca7400cb1afdcf62274a13f1d05fdfd953 100644 (file)
@@ -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() {
index ee3ce7ea47f31633f8017568c7686d2b165605c5..111aabbdf8f1f7da411c02683f24d895bd295e92 100644 (file)
@@ -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() {