11import { createStubRequest , LP_API } from '../src'
2+ import { LP_API_ACTION_NAMESPACE } from '../src/actions'
23import { REQUEST_TYPE } from './fixtures'
34
45describe ( 'createStubRequest' , ( ) => {
56 test ( 'requires a type argument' , ( ) => {
67 expect ( createStubRequest ) . toThrow ( )
78 } )
8-
9+
910 test ( 'accepts object data' , ( ) => {
1011 const stubData = { foo : 'bar' }
1112 const actionCreator = createStubRequest ( REQUEST_TYPE , stubData )
1213 const action = actionCreator ( )
1314 expect ( action [ LP_API ] ) . toEqual ( { type : REQUEST_TYPE , isStub : true , stubData } )
1415 } )
15-
16+
1617 test ( 'accepts function data creator' , ( ) => {
1718 const actionCreator = createStubRequest ( REQUEST_TYPE , ( arg ) => ( {
1819 foo : arg
1920 } ) )
2021 const action = actionCreator ( 'bar' )
2122 expect ( action [ LP_API ] ) . toEqual ( { type : REQUEST_TYPE , isStub : true , stubData : { foo : 'bar' } } )
2223 } )
23-
24+
2425 test ( 'accepts delay option' , ( ) => {
2526 const stubData = { foo : 'bar' }
2627 const actionCreator = createStubRequest ( REQUEST_TYPE , stubData , { delay : 500 } )
2728 const action = actionCreator ( )
2829 expect ( action [ LP_API ] ) . toEqual ( { type : REQUEST_TYPE , isStub :true , stubData, delay : 500 } )
2930 } )
30-
31+
3132 test ( 'function sets data and error flag from thrown exception' , ( ) => {
3233 const myException = new Error ( 'oops' )
3334 const actionCreator = createStubRequest ( REQUEST_TYPE , ( ) => {
@@ -36,14 +37,24 @@ describe('createStubRequest', () => {
3637 const action = actionCreator ( 'bar' )
3738 expect ( action [ LP_API ] ) . toEqual ( { type : REQUEST_TYPE , isStub : true , isStubError : true , stubData : myException } )
3839 } )
39-
40+
4041 test ( 'defaults to identity for data creator' , ( ) => {
4142 const actionCreator = createStubRequest ( REQUEST_TYPE )
4243 const action = actionCreator ( 'bar' )
4344 expect ( action [ LP_API ] ) . toEqual ( { type : REQUEST_TYPE , isStub : true , stubData : 'bar' } )
4445 } )
45-
46+
4647 test ( 'rejects other types of data definitions' , ( ) => {
4748 expect ( ( ) => createStubRequest ( REQUEST_TYPE , 'wtf' ) ) . toThrow ( )
4849 } )
50+
51+ test ( 'has the namespaced action type as its string representation' , ( ) => {
52+ const actionCreator = createStubRequest ( REQUEST_TYPE )
53+ expect ( actionCreator . toString ( ) ) . toEqual ( LP_API_ACTION_NAMESPACE + REQUEST_TYPE )
54+ } )
55+
56+ test ( 'has the namespaced action type set to the special `type` property' , ( ) => {
57+ const actionCreator = createStubRequest ( REQUEST_TYPE )
58+ expect ( actionCreator . type ) . toEqual ( LP_API_ACTION_NAMESPACE + REQUEST_TYPE )
59+ } )
4960} )
0 commit comments