Skip to content

Commit

Permalink
revert Plots object in register,
Browse files Browse the repository at this point in the history
- so that Plots is consistent from suite to suite.
  • Loading branch information
etpinard committed Feb 15, 2016
1 parent d46ae26 commit 02eca97
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/jasmine/tests/register_test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
var Plotly = require('@lib/index');

describe('the register function', function() {
'use strict';

var Plots = Plotly.Plots;

beforeEach(function() {
this.modulesKeys = Object.keys(Plots.modules);
this.allTypesKeys = Object.keys(Plots.allTypes);
this.allCategoriesKeys = Object.keys(Plots.allCategories);
});

afterEach(function() {
function revertObj(obj, initialKeys) {
Object.keys(obj).forEach(function(k) {
if(initialKeys.indexOf(k) === -1) delete obj[k];
});
}

revertObj(Plots.modules, this.modulesKeys);
revertObj(Plots.allTypes, this.allTypesKeys);
revertObj(Plots.allCategories, this.allCategoriesKeys);
});

it('should throw an error when no argument is given', function() {
expect(function() {
Expand Down

1 comment on commit 02eca97

@etpinard
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdtusz Working with karma-browserify, we have to be careful when mutation internal objects in our tests.

Here, the register tests were adding trace types to Plots meaning that subsequent Plotly.plot calls were looking for _module that didn't exist on this line.

The revertObj routine was adapted from plots_test.

Please sign in to comment.