Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions lib/node_modules/@stdlib/plot/vega/scale/base/ctor/test/test.domain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var tape = require( 'tape' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var isUndefined = require( '@stdlib/assert/is-undefined' );
var hasProp = require( '@stdlib/assert/has-property' );
var isCollection = require( '@stdlib/assert/is-collection' );
var Scale = require( './../lib' );


// TESTS //

tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof Scale, 'function', 'main export is a function' );
t.end();
});

tape( 'the constructor returns an instance which has a `domain` property', function test( t ) {
var v;

v = new Scale({
'name': 'xScale'
});
t.strictEqual( hasOwnProp( v, 'domain' ), false, 'returns expected value' );
t.strictEqual( hasProp( v, 'domain' ), true, 'returns expected value' );
t.strictEqual( isUndefined( v.domain ), true, 'returns expected value' );

v = new Scale({
'name': 'xScale',
'domain': [ 0, 10 ]
});
t.strictEqual( isCollection( v.domain ), true, 'returns expected value' );

t.end();
});

tape( 'the constructor returns an instance having a `domain` property which throws an error if set to an invalid value', function test( t ) {
var values;
var i;
var v;

v = new Scale({
'name': 'xScale'
});

values = [
'5',
5,
NaN,
true,
false,
function noop() {}
];
for ( i = 0; i < values.length; i++ ) {
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
}
t.end();

function badValue( value ) {
return function badValue() {
v.domain = value;
};
}
});

tape( 'the constructor returns an instance having a `domain` property', function test( t ) {
var scale;

scale = new Scale({
'name': 'xScale'
});
t.strictEqual( isUndefined( scale.domain ), true, 'returns expected value' );

scale = new Scale({
'name': 'xScale',
'domain': [ 0, 10 ]
});
t.deepEqual( scale.domain, [ 0, 10 ], 'returns expected value' );

scale = new Scale({
'name': 'xScale',
'domain': [ 0, 20 ]
});
t.deepEqual( scale.domain, [ 0, 20 ], 'returns expected value' );

t.end();
});

tape( 'the constructor returns an instance having a `domain` property which can be set to a valid value', function test( t ) {
var scale;

scale = new Scale({
'name': 'xScale'
});

scale.domain = [ 0, 10 ];
t.deepEqual( scale.domain, [ 0, 10 ], 'returns expected value' );

scale.domain = [ 0, 20 ];
t.deepEqual( scale.domain, [ 0, 20 ], 'returns expected value' );

t.end();
});

tape( 'the constructor returns an instance which emits an event when the `domain` property is set to a new value', function test( t ) {
var scale;
var count;

scale = new Scale({
'name': 'xScale'
});
count = 0;

scale.on( 'change', onChange );

scale.domain = [ 0, 10 ];
t.strictEqual( count, 1, 'returns expected value' );

scale.domain = [ 0, 20 ];
t.strictEqual( count, 2, 'returns expected value' );

// Setting to the same value should not emit an event:
scale.domain = [ 0, 20 ];
t.strictEqual( count, 2, 'returns expected value' );

t.end();

function onChange() {
count += 1;
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var tape = require( 'tape' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var isUndefined = require( '@stdlib/assert/is-undefined' );
var hasProp = require( '@stdlib/assert/has-property' );
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
var Scale = require( './../lib' );


// TESTS //

tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof Scale, 'function', 'main export is a function' );
t.end();
});

tape( 'the constructor returns an instance which has a `domainMax` property', function test( t ) {
var v;

v = new Scale({
'name': 'xScale'
});
t.strictEqual( hasOwnProp( v, 'domainMax' ), false, 'returns expected value' );
t.strictEqual( hasProp( v, 'domainMax' ), true, 'returns expected value' );
t.strictEqual( isUndefined( v.domainMax ), true, 'returns expected value' );

v = new Scale({
'name': 'xScale',
'domainMax': 10
});
t.strictEqual( isNumber( v.domainMax ), true, 'returns expected value' );

t.end();
});

tape( 'the constructor returns an instance having a `domainMax` property which throws an error if set to an invalid value', function test( t ) {
var values;
var i;
var v;

v = new Scale({
'name': 'xScale'
});

values = [
'5',
null,
true,
false,
[],
{},
function noop() {}
];
for ( i = 0; i < values.length; i++ ) {
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
}
t.end();

function badValue( value ) {
return function badValue() {
v.domainMax = value;
};
}
});

tape( 'the constructor returns an instance having a `domainMax` property', function test( t ) {
var scale;

scale = new Scale({
'name': 'xScale'
});
t.strictEqual( isUndefined( scale.domainMax ), true, 'returns expected value' );

scale = new Scale({
'name': 'xScale',
'domainMax': 10
});
t.strictEqual( scale.domainMax, 10, 'returns expected value' );

scale = new Scale({
'name': 'xScale',
'domainMax': 20
});
t.strictEqual( scale.domainMax, 20, 'returns expected value' );

t.end();
});

tape( 'the constructor returns an instance having a `domainMax` property which can be set to a valid value', function test( t ) {
var scale;

scale = new Scale({
'name': 'xScale'
});

scale.domainMax = 10;
t.strictEqual( scale.domainMax, 10, 'returns expected value' );

scale.domainMax = 20;
t.strictEqual( scale.domainMax, 20, 'returns expected value' );

t.end();
});

tape( 'the constructor returns an instance which emits an event when the `domainMax` property is set to a new value', function test( t ) {
var scale;
var count;

scale = new Scale({
'name': 'xScale'
});
count = 0;

scale.on( 'change', onChange );

scale.domainMax = 10;
t.strictEqual( count, 1, 'returns expected value' );

scale.domainMax = 20;
t.strictEqual( count, 2, 'returns expected value' );

// Setting to the same value should not emit an event:
scale.domainMax = 20;
t.strictEqual( count, 2, 'returns expected value' );

t.end();

function onChange() {
count += 1;
}
});
Loading
Loading