-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test: add tests for Autosize constructor and properties #9485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kgryte
merged 6 commits into
stdlib-js:refactor/plot
from
gururaj1512:refactor/plot-vega-autosize-ctor-tests
Mar 11, 2026
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
44aa4c6
feat: add tests for Autosize constructor and properties
gururaj1512 e711a72
Update test description
gururaj1512 086b2da
chore: update copyright years
stdlib-bot 4a60b27
chore: apply suggested changes
gururaj1512 c6bc74a
chore: clean-up
kgryte ff8155e
test: remove unused require
kgryte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
165 changes: 165 additions & 0 deletions
165
lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.contains.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| /** | ||
| * @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 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( 'attached to the prototype of the main export is a `contains` property for determining how a size calculation should be performed', function test( t ) { | ||
| t.strictEqual( hasOwnProp( Autosize.prototype, 'contains' ), true, 'has property' ); | ||
|
gururaj1512 marked this conversation as resolved.
Outdated
|
||
| 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, 'emits event' ); | ||
|
|
||
| autosize.contains = 'content'; | ||
| t.strictEqual( count, 2, 'emits event' ); | ||
|
|
||
| // Setting to the same value should not emit an event: | ||
| autosize.contains = 'content'; | ||
| t.strictEqual( count, 2, 'does not emit event when value is unchanged' ); | ||
|
gururaj1512 marked this conversation as resolved.
Outdated
|
||
|
|
||
| t.end(); | ||
|
|
||
| function onChange() { | ||
| count += 1; | ||
| } | ||
| }); | ||
181 changes: 181 additions & 0 deletions
181
lib/node_modules/@stdlib/plot/vega/autosize/ctor/test/test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ), 'serializes as JSON when called by JSON.stringify()' ); | ||
|
gururaj1512 marked this conversation as resolved.
Outdated
|
||
| 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', 'has `on` method' ); | ||
| t.strictEqual( typeof autosize.emit, 'function', 'has `emit` method' ); | ||
| t.strictEqual( typeof autosize.removeListener, 'function', 'has `removeListener` method' ); | ||
|
gururaj1512 marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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, 'does not have property' ); | ||
| t.strictEqual( hasOwnProp( autosize, 'foo' ), false, 'does not have property' ); | ||
|
gururaj1512 marked this conversation as resolved.
Outdated
|
||
|
|
||
| t.end(); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.