@@ -112,17 +112,22 @@ describe("ServiceFactory", () => {
112
112
describe ( "create" , ( ) => {
113
113
itReturnsFunction ( ServiceFactory . create , baseEndpoint ) ;
114
114
115
- it ( "given null, throws error" , async ( ) => {
116
- expect . assertions ( 1 ) ;
117
- try {
118
- const sut = ServiceFactory . create (
119
- StubResourceRecord ,
120
- baseEndpoint
121
- ) ;
122
- await sut ( null as any ) ; // <----- passing null
123
- } catch ( e ) {
124
- expect ( e ) . toBeInstanceOf ( TypeError ) ;
125
- }
115
+ it ( "given no arguments, throws error" , async ( ) => {
116
+ // Arrange
117
+ const expected = Factory . build < StubResourceRecord > (
118
+ FactoryType . StubResourceRecord
119
+ ) ;
120
+
121
+ const sut = ServiceFactory . create ( StubResourceRecord , baseEndpoint ) ;
122
+ mockPostSuccess ( expected ) ;
123
+
124
+ // Act
125
+ const response = await sut ( ) ;
126
+
127
+ // Assert
128
+ expect ( response . resultObject ) . not . toBeNull ( ) ;
129
+ expect ( response . resultObject ) . toBeInstanceOf ( StubResourceRecord ) ;
130
+ expect ( response . resultObject ! . name ) . toEqual ( expected . name ) ;
126
131
} ) ;
127
132
128
133
it ( "when successful, returns response mapped to supplied TRecord" , async ( ) => {
@@ -310,17 +315,24 @@ describe("ServiceFactory", () => {
310
315
itReturnsFunction ( ServiceFactory . nestedCreate , nestedBaseEndpoint ) ;
311
316
312
317
it ( "given null, throws error" , async ( ) => {
313
- expect . assertions ( 1 ) ;
314
- try {
315
- const sut = ServiceFactory . nestedCreate (
316
- StubResourceRecord ,
317
- baseEndpoint
318
- ) ;
319
-
320
- await sut ( null as any , { } ) ; // <----- passing null
321
- } catch ( e ) {
322
- expect ( e ) . toBeInstanceOf ( TypeError ) ;
323
- }
318
+ // Arrange
319
+ const expected = Factory . build < StubResourceRecord > (
320
+ FactoryType . StubResourceRecord
321
+ ) ;
322
+
323
+ const sut = ServiceFactory . nestedCreate (
324
+ StubResourceRecord ,
325
+ baseEndpoint
326
+ ) ;
327
+ mockPostSuccess ( expected ) ;
328
+
329
+ // Act
330
+ const response = await sut ( null , { } ) ;
331
+
332
+ // Assert
333
+ expect ( response . resultObject ) . not . toBeNull ( ) ;
334
+ expect ( response . resultObject ) . toBeInstanceOf ( StubResourceRecord ) ;
335
+ expect ( response . resultObject ! . name ) . toEqual ( expected . name ) ;
324
336
} ) ;
325
337
326
338
it ( "when successful, returns response mapped to supplied TRecord" , async ( ) => {
0 commit comments