@@ -10,28 +10,28 @@ describe('createCanal', () => {
1010 it ( 'throws an error if first arg is not a Component' , ( ) => {
1111 try {
1212 // @ts -ignore
13- createCanal ( ' aaa') ;
13+ createCanal ( { name : 'a' , Component : ' aaa' } ) ;
1414 } catch ( error ) {
1515 expect ( error . message ) . toBe (
16- '`createCanal` expects its arguments to be React components. Received type for argument 1: string '
16+ '`createCanal` could not find a valid `Component` key for argument 1. Received: {"name":"a","Component":"aaa"} '
1717 ) ;
1818 }
1919 expect . assertions ( 1 ) ;
2020 } ) ;
2121
2222 it ( 'renders the first page when mounted' , ( ) => {
23- const Transitioner = createCanal ( View ) ;
23+ const Transitioner = createCanal ( { name : 'a' , Component : View } ) ;
2424 const testRenderer = TestRenderer . create ( < Transitioner /> ) ;
2525 expect ( testRenderer . toJSON ( ) ) . toMatchSnapshot ( ) ;
2626 } ) ;
2727
2828 it ( 'throws an error if any arg is not a Component' , ( ) => {
2929 try {
3030 // @ts -ignore
31- createCanal ( View , ' aaa') ;
31+ createCanal ( { name : 'a' , Component : View } , { name : 'b' , Component : ' aaa' } ) ;
3232 } catch ( error ) {
3333 expect ( error . message ) . toBe (
34- '`createCanal` expects its arguments to be React components. Received type for argument 2: string '
34+ '`createCanal` could not find a valid `Component` key for argument 2. Received: {"name":"b","Component":"aaa"} '
3535 ) ;
3636 }
3737 expect . assertions ( 1 ) ;
@@ -40,8 +40,14 @@ describe('createCanal', () => {
4040 it ( 'emits the new canal to the navigation store' , ( ) => {
4141 const PageOne = ( ) => < View /> ;
4242 const PageTwo = ( ) => < View /> ;
43- const Transitioner = createCanal ( PageOne , PageTwo ) ;
44- const expectedCanal = new Canal ( [ PageOne , PageTwo ] ) ;
43+ const Transitioner = createCanal (
44+ { name : 'pageOne' , Component : PageOne } ,
45+ { name : 'pageTwo' , Component : PageTwo }
46+ ) ;
47+ const expectedCanal = new Canal ( [
48+ { name : 'pageOne' , Component : PageOne } ,
49+ { name : 'pageTwo' , Component : PageTwo } ,
50+ ] ) ;
4551 Navigation . getInstance ( ) . canalsSubject . subscribe ( {
4652 next : canal => {
4753 expect ( canal ) . toEqual ( expectedCanal ) ;
@@ -50,4 +56,27 @@ describe('createCanal', () => {
5056 TestRenderer . create ( < Transitioner /> ) ;
5157 expect . assertions ( 1 ) ;
5258 } ) ;
59+
60+ it ( 'throws an error if name is missing' , ( ) => {
61+ try {
62+ // @ts -ignore
63+ createCanal ( { Component : View } ) ;
64+ } catch ( error ) {
65+ expect ( error . message ) . toBe (
66+ '`createCanal` could not find a valid `name` key for argument 1. Received: {}'
67+ ) ;
68+ }
69+ expect . assertions ( 1 ) ;
70+ } ) ;
71+
72+ // @TODO 19-08-01 Pass this test
73+ xit ( 'throws an error some names are duplicated' , ( ) => {
74+ try {
75+ // @ts -ignore
76+ createCanal ( { name : 'a' , Component : View } , { name : 'a' , Component : View } ) ;
77+ } catch ( error ) {
78+ expect ( error . message ) . toBe ( '`createCanal` found duplicated `name: a` key.' ) ;
79+ }
80+ expect . assertions ( 1 ) ;
81+ } ) ;
5382} ) ;
0 commit comments