https://github.com/plotly/plotly.js
Raw File
Tip revision: 32d46313a6c7dcdd46ebb608f7a18ce70201645a authored by archmoj on 22 April 2021, 15:01:59 UTC
2.0.0-rc.1
Tip revision: 32d4631
test_plain_obj.js
var jsdom = require('jsdom');
var fs = require('fs');

var plotlyServerDom = new jsdom.JSDOM('', { runScripts: 'dangerously'});
// Mock a few things that jsdom doesn't support out-of-the-box
plotlyServerDom.window.URL.createObjectURL = function() {};

// Run Plotly inside jsdom
var plotlyJsPath = require.resolve('../dist/plotly.js');
var plotlyJsSource = fs.readFileSync(plotlyJsPath, 'utf-8');
plotlyServerDom.window.eval(plotlyJsSource);

var assertValidate = function(fig, exp) {
    console.log(fig);

    var errorList = plotlyServerDom.window.Plotly.validate(fig.data, fig.layout);

    if(exp) {
        if(errorList !== undefined) throw 'should be valid:';
    } else {
        if(errorList === undefined) throw 'should not be valid:';
    }
};

assertValidate({
    data: [{ y: [1] }],
    layout: {}
}, true);

assertValidate({
    data: [{ z: false }],
    layout: {}
}, false);
back to top