|
| 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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; |
| 27 | +var Padding = 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 Padding, 'function', 'main export is a function' ); |
| 35 | + t.end(); |
| 36 | +}); |
| 37 | + |
| 38 | +tape( 'the constructor returns an instance which has a `bottom` property', function test( t ) { |
| 39 | + var v; |
| 40 | + |
| 41 | + v = new Padding(); |
| 42 | + t.strictEqual( hasOwnProp( v, 'bottom' ), false, 'returns expected value' ); |
| 43 | + t.strictEqual( hasProp( v, 'bottom' ), true, 'returns expected value' ); |
| 44 | + t.strictEqual( isNumber( v.bottom ), true, 'returns expected value' ); |
| 45 | + |
| 46 | + t.end(); |
| 47 | +}); |
| 48 | + |
| 49 | +tape( 'the constructor returns an instance having a `bottom` property which throws an error if set to an invalid value', function test( t ) { |
| 50 | + var values; |
| 51 | + var i; |
| 52 | + |
| 53 | + values = [ |
| 54 | + 'beep', |
| 55 | + 'boop', |
| 56 | + null, |
| 57 | + true, |
| 58 | + false, |
| 59 | + [], |
| 60 | + {}, |
| 61 | + function noop() {} |
| 62 | + ]; |
| 63 | + for ( i = 0; i < values.length; i++ ) { |
| 64 | + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); |
| 65 | + } |
| 66 | + t.end(); |
| 67 | + |
| 68 | + function badValue( value ) { |
| 69 | + return function badValue() { |
| 70 | + var padding = new Padding(); |
| 71 | + padding.bottom = value; |
| 72 | + }; |
| 73 | + } |
| 74 | +}); |
| 75 | + |
| 76 | +tape( 'the constructor returns an instance having a `bottom` property', function test( t ) { |
| 77 | + var padding; |
| 78 | + |
| 79 | + padding = new Padding(); |
| 80 | + t.strictEqual( padding.bottom, 0, 'returns expected value' ); |
| 81 | + |
| 82 | + padding = new Padding({ |
| 83 | + 'bottom': 10 |
| 84 | + }); |
| 85 | + t.strictEqual( padding.bottom, 10, 'returns expected value' ); |
| 86 | + |
| 87 | + padding = new Padding({ |
| 88 | + 'bottom': 20 |
| 89 | + }); |
| 90 | + t.strictEqual( padding.bottom, 20, 'returns expected value' ); |
| 91 | + |
| 92 | + t.end(); |
| 93 | +}); |
| 94 | + |
| 95 | +tape( 'the constructor returns an instance having a `bottom` property which can be set to a valid value', function test( t ) { |
| 96 | + var padding; |
| 97 | + |
| 98 | + padding = new Padding(); |
| 99 | + |
| 100 | + padding.bottom = 10; |
| 101 | + t.strictEqual( padding.bottom, 10, 'returns expected value' ); |
| 102 | + |
| 103 | + padding.bottom = 20; |
| 104 | + t.strictEqual( padding.bottom, 20, 'returns expected value' ); |
| 105 | + |
| 106 | + t.end(); |
| 107 | +}); |
| 108 | + |
| 109 | +tape( 'the constructor returns an instance which emits an event when the `bottom` property is set to a new value', function test( t ) { |
| 110 | + var padding; |
| 111 | + var count; |
| 112 | + |
| 113 | + padding = new Padding(); |
| 114 | + count = 0; |
| 115 | + |
| 116 | + padding.on( 'change', onChange ); |
| 117 | + |
| 118 | + padding.bottom = 10; |
| 119 | + t.strictEqual( count, 1, 'returns expected value' ); |
| 120 | + |
| 121 | + padding.bottom = 20; |
| 122 | + t.strictEqual( count, 2, 'returns expected value' ); |
| 123 | + |
| 124 | + // Setting to the same value should not emit an event: |
| 125 | + padding.bottom = 20; |
| 126 | + t.strictEqual( count, 2, 'returns expected value' ); |
| 127 | + |
| 128 | + t.end(); |
| 129 | + |
| 130 | + function onChange() { |
| 131 | + count += 1; |
| 132 | + } |
| 133 | +}); |
0 commit comments