Skip to content

Commit 1b58bf0

Browse files
committed
Auto-generated commit
1 parent 07285d8 commit 1b58bf0

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2025-09-08)
7+
## Unreleased (2025-09-10)
88

99
<section class="features">
1010

@@ -35,6 +35,7 @@ This release closes the following issue:
3535

3636
<details>
3737

38+
- [`d8ad76b`](https://github.com/stdlib-js/stdlib/commit/d8ad76b37fa2b01cd66585f6389f415f61246a63) - **test:** add tests for `toJSON` method in `dstructs/named-typed-tuple` [(#8049)](https://github.com/stdlib-js/stdlib/pull/8049) _(by Gaurav Kaushik, Athan Reines)_
3839
- [`a540e07`](https://github.com/stdlib-js/stdlib/commit/a540e076b9bfeacd4c7e85add92d095f1ca042bf) - **test:** add tests for `forEach` method in `dstructs/named-typed-tuple` [(#8042)](https://github.com/stdlib-js/stdlib/pull/8042) _(by Gaurav Kaushik, Athan Reines)_
3940
- [`f501596`](https://github.com/stdlib-js/stdlib/commit/f501596714b0f5d5d54416aefba7fff57b000760) - **test:** add tests for `toString` method in `dstructs/named-typed-tuple` [(#8041)](https://github.com/stdlib-js/stdlib/pull/8041) _(by Gaurav Kaushik, Athan Reines)_
4041
- [`5d9761c`](https://github.com/stdlib-js/stdlib/commit/5d9761cfdea3389f82ca75aa262a9fc3ddf89439) - **feat:** implement `toLocaleString` method in `dstructs/named-typed-tuple` [(#8009)](https://github.com/stdlib-js/stdlib/pull/8009) _(by Gaurav Kaushik, Athan Reines, stdlib-bot)_

test/test.to_json.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 isFunction = require( '@stdlib/assert-is-function' );
26+
var namedtypedtuple = require( './../lib' );
27+
28+
29+
// TESTS //
30+
31+
tape( 'main export is a function', function test( t ) {
32+
t.ok( true, __filename );
33+
t.strictEqual( typeof namedtypedtuple, 'function', 'main export is a function' );
34+
t.end();
35+
});
36+
37+
tape( 'a tuple has a `toJSON` method', function test( t ) {
38+
var Point;
39+
var p;
40+
41+
Point = namedtypedtuple( [ 'x', 'y' ], {
42+
'name': 'Point'
43+
});
44+
p = new Point( [ 10, 20 ] );
45+
46+
t.strictEqual( hasOwnProp( p, 'toJSON' ), true, 'returns expected value' );
47+
t.strictEqual( isFunction( p.toJSON ), true, 'returns expected value' );
48+
t.end();
49+
});
50+
51+
tape( 'the method throws an error if invoked with a `this` context which is not a tuple instance', function test( t ) {
52+
var values;
53+
var Point;
54+
var p;
55+
var i;
56+
57+
Point = namedtypedtuple( [ 'x', 'y' ], {
58+
'name': 'Point'
59+
});
60+
p = new Point( [ 10, 20 ] );
61+
62+
values = [
63+
'5',
64+
5,
65+
NaN,
66+
true,
67+
false,
68+
null,
69+
void 0,
70+
{},
71+
[],
72+
function noop() {},
73+
{
74+
'name': 'Bob'
75+
}
76+
];
77+
for ( i = 0; i < values.length; i++ ) {
78+
t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] );
79+
}
80+
t.end();
81+
82+
function badValue( value ) {
83+
return function badValue() {
84+
return p.toJSON.call( value );
85+
};
86+
}
87+
});
88+
89+
tape( 'the method serializes a tuple as JSON', function test( t ) {
90+
var expected;
91+
var actual;
92+
var Point;
93+
var p;
94+
95+
Point = namedtypedtuple( [ 'x', 'y' ] );
96+
p = new Point( [ 10, 20 ] );
97+
98+
expected = {
99+
'x': 10,
100+
'y': 20
101+
};
102+
actual = p.toJSON();
103+
104+
t.deepEqual( actual, expected, 'returns expected value' );
105+
t.end();
106+
});

0 commit comments

Comments
 (0)