1
1
import { beforeEach , describe , expect } from "vitest" ;
2
2
import { Given , When , Then } from "./gherkin.js" ;
3
3
import * as JsonPointer from "./index.js" ;
4
- import type { Json , JsonObject , Pointable } from "./index.js" ;
4
+
5
+ /**
6
+ * @import { Json, JsonObject } from "./index.js"
7
+ */
5
8
6
9
7
10
describe ( "JsonPointer.assign" , ( ) => {
@@ -13,7 +16,7 @@ describe("JsonPointer.assign", () => {
13
16
JsonPointer . assign ( pointer , subject , "foo" ) ;
14
17
15
18
Then ( "the value is not changed" , ( ) => {
16
- expect ( subject ) . to . eql ( { " foo" : "bar" } ) ;
19
+ expect ( subject ) . to . eql ( { foo : "bar" } ) ;
17
20
} ) ;
18
21
} ) ;
19
22
} ) ;
@@ -22,7 +25,7 @@ describe("JsonPointer.assign", () => {
22
25
const pointer = "/aaa" ;
23
26
24
27
When ( "mutating a property" , ( ) => {
25
- const subject = { " aaa" : 111 , " bbb" : [ ] } ;
28
+ const subject = { aaa : 111 , bbb : [ ] } ;
26
29
JsonPointer . assign ( pointer , subject , "foo" ) ;
27
30
28
31
Then ( "the new value should be set" , ( ) => {
@@ -48,7 +51,7 @@ describe("JsonPointer.assign", () => {
48
51
const pointer = "/aaa/ccc" ;
49
52
50
53
When ( "mutating a property" , ( ) => {
51
- const subject = { " aaa" : { " ccc" : 333 , " ddd" : 444 } , " bbb" : 222 } ;
54
+ const subject = { aaa : { ccc : 333 , ddd : 444 } , bbb : 222 } ;
52
55
JsonPointer . assign ( pointer , subject , "foo" ) ;
53
56
54
57
Then ( "the new value should be set" , ( ) => {
@@ -58,7 +61,8 @@ describe("JsonPointer.assign", () => {
58
61
} ) ;
59
62
60
63
Given ( "an object" , ( ) => {
61
- let subject : JsonObject ;
64
+ /** @type JsonObject */
65
+ let subject ;
62
66
63
67
beforeEach ( ( ) => {
64
68
subject = { aaa : { bbb : { } } } ;
@@ -84,7 +88,8 @@ describe("JsonPointer.assign", () => {
84
88
} ) ;
85
89
86
90
Given ( "an array" , ( ) => {
87
- let subject : Json [ ] ;
91
+ /** @type Json[] */
92
+ let subject ;
88
93
89
94
beforeEach ( ( ) => {
90
95
subject = [ ] ;
@@ -112,7 +117,8 @@ describe("JsonPointer.assign", () => {
112
117
} ) ;
113
118
114
119
Given ( "a number" , ( ) => {
115
- let subject : unknown ;
120
+ /** @type number */
121
+ let subject ;
116
122
117
123
beforeEach ( ( ) => {
118
124
subject = 42 ;
@@ -122,13 +128,14 @@ describe("JsonPointer.assign", () => {
122
128
const assign = JsonPointer . assign ( "/0" ) ;
123
129
124
130
Then ( "an error should be thrown" , ( ) => {
125
- expect ( ( ) => assign ( subject as Pointable , "foo" ) ) . to . throw ( Error , "Value at '' is a number and does not have property '0'" ) ;
131
+ expect ( ( ) => assign ( subject , "foo" ) ) . to . throw ( Error , "Value at '' is a number and does not have property '0'" ) ;
126
132
} ) ;
127
133
} ) ;
128
134
} ) ;
129
135
130
136
Given ( "a string" , ( ) => {
131
- let subject : unknown ;
137
+ /** @type string */
138
+ let subject ;
132
139
133
140
beforeEach ( ( ) => {
134
141
subject = "foo" ;
@@ -138,13 +145,14 @@ describe("JsonPointer.assign", () => {
138
145
const assign = JsonPointer . assign ( "/0" ) ;
139
146
140
147
Then ( "an error should be thrown" , ( ) => {
141
- expect ( ( ) => assign ( subject as Pointable , "foo" ) ) . to . throw ( Error , "Value at '' is a string and does not have property '0'" ) ;
148
+ expect ( ( ) => assign ( subject , "foo" ) ) . to . throw ( Error , "Value at '' is a string and does not have property '0'" ) ;
142
149
} ) ;
143
150
} ) ;
144
151
} ) ;
145
152
146
153
Given ( "null" , ( ) => {
147
- let subject : unknown ;
154
+ /** @type null */
155
+ let subject ;
148
156
149
157
beforeEach ( ( ) => {
150
158
subject = null ;
@@ -154,7 +162,7 @@ describe("JsonPointer.assign", () => {
154
162
const assign = JsonPointer . assign ( "/0" ) ;
155
163
156
164
Then ( "an error should be thrown" , ( ) => {
157
- expect ( ( ) => assign ( subject as Pointable , "foo" ) ) . to . throw ( Error , "Value at '' is null and does not have property '0'" ) ;
165
+ expect ( ( ) => assign ( subject , "foo" ) ) . to . throw ( Error , "Value at '' is null and does not have property '0'" ) ;
158
166
} ) ;
159
167
} ) ;
160
168
} ) ;
0 commit comments