Skip to content

Commit 275850a

Browse files
Sachinn-64kgrytegururaj1512
authored
test: add tests for Axis constructor and properties
PR-URL: #10414 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Co-authored-by: Gururaj Gurram <gururajgurram1512@gmail.com> Reviewed-by: Gururaj Gurram <gururajgurram1512@gmail.com> Signed-off-by: Sachin Pangal <sachinprogramming62@gmail.com> Signed-off-by: Athan Reines <kgryte@gmail.com>
1 parent 3a999dd commit 275850a

79 files changed

Lines changed: 14655 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25+
var hasProp = require( '@stdlib/assert/has-property' );
26+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
27+
var Axis = require( './../lib' );
28+
29+
30+
// TESTS //
31+
32+
tape( 'main export is a function', function test( t ) {
33+
t.ok( true, __filename );
34+
t.strictEqual( typeof Axis, 'function', 'main export is a function' );
35+
t.end();
36+
});
37+
38+
tape( 'the constructor returns an instance which has an `aria` property', function test( t ) {
39+
var v;
40+
41+
v = new Axis({
42+
'scale': 'xScale',
43+
'orient': 'bottom'
44+
});
45+
t.strictEqual( hasOwnProp( v, 'aria' ), false, 'returns expected value' );
46+
t.strictEqual( hasProp( v, 'aria' ), true, 'returns expected value' );
47+
t.strictEqual( isBoolean( v.aria ), true, 'returns expected value' );
48+
t.end();
49+
});
50+
51+
tape( 'the constructor returns an instance having an `aria` property which throws an error if set to a non-boolean value', function test( t ) {
52+
var values;
53+
var i;
54+
55+
values = [
56+
'5',
57+
5,
58+
NaN,
59+
null,
60+
void 0,
61+
[],
62+
{},
63+
function noop() {}
64+
];
65+
for ( i = 0; i < values.length; i++ ) {
66+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
67+
}
68+
t.end();
69+
70+
function badValue( value ) {
71+
return function badValue() {
72+
var axis = new Axis({
73+
'scale': 'xScale',
74+
'orient': 'bottom'
75+
});
76+
axis.aria = value;
77+
};
78+
}
79+
});
80+
81+
tape( 'the constructor returns an instance having an `aria` property', function test( t ) {
82+
var axis;
83+
84+
axis = new Axis({
85+
'scale': 'xScale',
86+
'orient': 'bottom'
87+
});
88+
t.strictEqual( axis.aria, true, 'returns expected value' );
89+
90+
axis = new Axis({
91+
'scale': 'xScale',
92+
'orient': 'bottom',
93+
'aria': false
94+
});
95+
t.strictEqual( axis.aria, false, 'returns expected value' );
96+
97+
axis = new Axis({
98+
'scale': 'xScale',
99+
'orient': 'bottom',
100+
'aria': true
101+
});
102+
t.strictEqual( axis.aria, true, 'returns expected value' );
103+
104+
t.end();
105+
});
106+
107+
tape( 'the constructor returns an instance having an `aria` property which can be set to a boolean', function test( t ) {
108+
var axis;
109+
110+
axis = new Axis({
111+
'scale': 'xScale',
112+
'orient': 'bottom'
113+
});
114+
115+
axis.aria = true;
116+
t.strictEqual( axis.aria, true, 'returns expected value' );
117+
118+
axis.aria = false;
119+
t.strictEqual( axis.aria, false, 'returns expected value' );
120+
121+
t.end();
122+
});
123+
124+
tape( 'the constructor returns an instance which emits an event when the `aria` property is set to a new value', function test( t ) {
125+
var count;
126+
var axis;
127+
128+
axis = new Axis({
129+
'scale': 'xScale',
130+
'orient': 'bottom'
131+
});
132+
count = 0;
133+
134+
axis.on( 'change', onChange );
135+
136+
axis.aria = false;
137+
t.strictEqual( count, 1, 'returns expected value' );
138+
139+
axis.aria = true;
140+
t.strictEqual( count, 2, 'returns expected value' );
141+
142+
// Setting to the same value should not emit an event:
143+
axis.aria = true;
144+
t.strictEqual( count, 2, 'returns expected value' );
145+
146+
t.end();
147+
148+
function onChange() {
149+
count += 1;
150+
}
151+
});
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25+
var isUndefined = require( '@stdlib/assert/is-undefined' );
26+
var hasProp = require( '@stdlib/assert/has-property' );
27+
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
28+
var Axis = require( './../lib' );
29+
30+
31+
// TESTS //
32+
33+
tape( 'main export is a function', function test( t ) {
34+
t.ok( true, __filename );
35+
t.strictEqual( typeof Axis, 'function', 'main export is a function' );
36+
t.end();
37+
});
38+
39+
tape( 'the constructor returns an instance which has a `bandPosition` property', function test( t ) {
40+
var v;
41+
42+
v = new Axis({
43+
'scale': 'xScale',
44+
'orient': 'bottom'
45+
});
46+
t.strictEqual( hasOwnProp( v, 'bandPosition' ), false, 'returns expected value' );
47+
t.strictEqual( hasProp( v, 'bandPosition' ), true, 'returns expected value' );
48+
t.strictEqual( isUndefined( v.bandPosition ), true, 'returns expected value' );
49+
50+
v = new Axis({
51+
'scale': 'xScale',
52+
'orient': 'bottom',
53+
'bandPosition': 0.5
54+
});
55+
t.strictEqual( isNumber( v.bandPosition ), true, 'returns expected value' );
56+
57+
t.end();
58+
});
59+
60+
tape( 'the constructor returns an instance having a `bandPosition` property which throws an error if set to an invalid value', function test( t ) {
61+
var values;
62+
var i;
63+
64+
values = [
65+
'beep',
66+
-0.1,
67+
1.1,
68+
NaN,
69+
{},
70+
function noop() {}
71+
];
72+
for ( i = 0; i < values.length; i++ ) {
73+
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
74+
}
75+
t.end();
76+
77+
function badValue( value ) {
78+
return function badValue() {
79+
var axis = new Axis({
80+
'scale': 'xScale',
81+
'orient': 'bottom'
82+
});
83+
axis.bandPosition = value;
84+
};
85+
}
86+
});
87+
88+
tape( 'the constructor returns an instance having a `bandPosition` property', function test( t ) {
89+
var axis;
90+
91+
axis = new Axis({
92+
'scale': 'xScale',
93+
'orient': 'bottom'
94+
});
95+
t.strictEqual( isUndefined( axis.bandPosition ), true, 'returns expected value' );
96+
97+
axis = new Axis({
98+
'scale': 'xScale',
99+
'orient': 'bottom',
100+
'bandPosition': 0.5
101+
});
102+
t.strictEqual( axis.bandPosition, 0.5, 'returns expected value' );
103+
104+
t.end();
105+
});
106+
107+
tape( 'the constructor returns an instance having a `bandPosition` property which can be set to a valid value', function test( t ) {
108+
var axis;
109+
110+
axis = new Axis({
111+
'scale': 'xScale',
112+
'orient': 'bottom'
113+
});
114+
115+
axis.bandPosition = 0.5;
116+
t.strictEqual( axis.bandPosition, 0.5, 'returns expected value' );
117+
118+
axis.bandPosition = 0;
119+
t.strictEqual( axis.bandPosition, 0, 'returns expected value' );
120+
121+
axis.bandPosition = 1;
122+
t.strictEqual( axis.bandPosition, 1, 'returns expected value' );
123+
124+
t.end();
125+
});
126+
127+
tape( 'the constructor returns an instance which emits an event when the `bandPosition` property is set to a new value', function test( t ) {
128+
var count;
129+
var axis;
130+
131+
axis = new Axis({
132+
'scale': 'xScale',
133+
'orient': 'bottom'
134+
});
135+
count = 0;
136+
137+
axis.on( 'change', onChange );
138+
139+
axis.bandPosition = 0.5;
140+
t.strictEqual( count, 1, 'returns expected value' );
141+
142+
axis.bandPosition = 0.3;
143+
t.strictEqual( count, 2, 'returns expected value' );
144+
145+
// Setting to the same value should not emit an event:
146+
axis.bandPosition = 0.3;
147+
t.strictEqual( count, 2, 'returns expected value' );
148+
149+
t.end();
150+
151+
function onChange() {
152+
count += 1;
153+
}
154+
});

0 commit comments

Comments
 (0)