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
172 changes: 172 additions & 0 deletions lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.contains.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/**
* @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 hasProp = require( '@stdlib/assert/has-property' );
var isString = require( '@stdlib/assert/is-string' );
var Autosize = require( './../lib' );


// TESTS //

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

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

v = new Autosize();
t.strictEqual( hasOwnProp( v, 'contains' ), false, 'returns expected value' );
t.strictEqual( hasProp( v, 'contains' ), true, 'returns expected value' );
t.strictEqual( isString( v.contains ), true, 'returns expected value' );
t.end();
});

tape( 'the constructor throws an error if provided an invalid `contains` option', function test( t ) {
var values;
var i;

values = [
'beep',
'boop',
'invalid',
'CONTENT',
'PADDING',
5,
NaN,
null,
void 0,
true,
false,
[],
{},
function noop() {}
];
for ( i = 0; i < values.length; i++ ) {
t.throws( badValue( values[ i ] ), Error, 'throws an error when provided ' + values[ i ] );
}
t.end();

function badValue( value ) {
return function badValue() {
var autosize = new Autosize({ // eslint-disable-line no-unused-vars
'contains': value
});
};
}
});

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

values = [
'beep',
'boop',
'invalid',
'CONTENT',
'PADDING',
5,
NaN,
null,
void 0,
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() {
var autosize = new Autosize();
autosize.contains = value;
};
}
});

tape( 'the constructor returns an instance having a `contains` property which returns the method for determining how a size calculation should be performed', function test( t ) {
var autosize;

autosize = new Autosize();
t.strictEqual( autosize.contains, 'content', 'returns expected value' );

autosize = new Autosize({
'contains': 'padding'
});
t.strictEqual( autosize.contains, 'padding', 'returns expected value' );

autosize = new Autosize({
'contains': 'content'
});
t.strictEqual( autosize.contains, 'content', 'returns expected value' );

t.end();
});

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

autosize = new Autosize();

autosize.contains = 'padding';
t.strictEqual( autosize.contains, 'padding', 'returns expected value' );

autosize.contains = 'content';
t.strictEqual( autosize.contains, 'content', 'returns expected value' );

t.end();
});

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

autosize = new Autosize();
count = 0;

autosize.on( 'change', onChange );

autosize.contains = 'padding';
t.strictEqual( count, 1, 'returns expected value' );

autosize.contains = 'content';
t.strictEqual( count, 2, 'returns expected value' );

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

t.end();

function onChange() {
count += 1;
}
});
181 changes: 181 additions & 0 deletions lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/**
* @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 instanceOf = require( '@stdlib/assert/instance-of' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var Autosize = require( './../lib' );


// TESTS //

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

tape( 'the function is a constructor', function test( t ) {
var autosize = new Autosize();
t.strictEqual( instanceOf( autosize, Autosize ), true, 'returns expected value' );
t.end();
});

tape( 'the constructor does not require the `new` keyword', function test( t ) {
var autosize;
var ctor;

ctor = Autosize;
autosize = ctor();
t.strictEqual( instanceOf( autosize, Autosize ), true, 'returns expected value' );
t.end();
});

tape( 'the constructor does not require the `new` keyword (options)', function test( t ) {
var autosize;
var ctor;

ctor = Autosize;
autosize = ctor({
'type': 'fit'
});
t.strictEqual( instanceOf( autosize, Autosize ), true, 'returns expected value' );
t.strictEqual( autosize.type, 'fit', 'returns expected value' );
t.end();
});

tape( 'the constructor throws an error if provided an options argument which is not an object', function test( t ) {
var values;
var i;

values = [
'5',
5,
NaN,
null,
void 0,
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() {
var autosize = new Autosize( value ); // eslint-disable-line no-unused-vars
};
}
});

tape( 'the constructor has a read-only `name` property', function test( t ) {
t.strictEqual( Autosize.name, 'Autosize', 'returns expected value' );
t.end();
});

tape( 'the constructor returns an instance having a `toJSON` method for serializing an instance to JSON', function test( t ) {
var expected;
var autosize;
var json;

autosize = new Autosize();
json = autosize.toJSON();

expected = {
'contains': 'content',
'resize': false,
'type': 'pad'
};
t.deepEqual( json, expected, 'returns expected value' );
t.end();
});

tape( 'the constructor returns an instance having a `toJSON` method for serializing an instance to JSON (options)', function test( t ) {
var expected;
var autosize;
var json;

autosize = new Autosize({
'type': 'fit',
'contains': 'padding',
'resize': true
});
json = autosize.toJSON();

expected = {
'contains': 'padding',
'resize': true,
'type': 'fit'
};
t.deepEqual( json, expected, 'returns expected value' );
t.end();
});

tape( 'the `toJSON` method is implicitly invoked by `JSON.stringify`', function test( t ) {
var expected;
var autosize;

autosize = new Autosize({
'type': 'none',
'contains': 'content',
'resize': false
});

expected = {
'contains': 'content',
'resize': false,
'type': 'none'
};
t.strictEqual( JSON.stringify( autosize ), JSON.stringify( expected ), 'returns expected value' );
t.end();
});

tape( 'the constructor returns an instance which inherits from EventEmitter', function test( t ) {
var autosize;

autosize = new Autosize();

t.strictEqual( typeof autosize.on, 'function', 'returns expected value' );
t.strictEqual( typeof autosize.emit, 'function', 'returns expected value' );
t.strictEqual( typeof autosize.removeListener, 'function', 'returns expected value' );

t.end();
});

tape( 'the constructor ignores unrecognized options', function test( t ) {
var autosize;

autosize = new Autosize({
'type': 'fit',
'beep': 'boop',
'foo': 'bar'
});

t.strictEqual( autosize.type, 'fit', 'returns expected value' );
t.strictEqual( hasOwnProp( autosize, 'beep' ), false, 'returns expected value' );
t.strictEqual( hasOwnProp( autosize, 'foo' ), false, 'returns expected value' );

t.end();
});
Loading
Loading