@@ -244,9 +244,12 @@ describe("sampleFromSchema", function() {
244244 format : "date-time"
245245 }
246246
247- var expected = new Date ( ) . toISOString ( )
247+ // 0-20 chops off milliseconds
248+ // necessary because test latency can cause failures
249+ // it would be better to mock Date globally and expect a string - KS 11/18
250+ var expected = new Date ( ) . toISOString ( ) . substring ( 0 , 20 )
248251
249- expect ( sampleFromSchema ( definition ) ) . toEqual ( expected )
252+ expect ( sampleFromSchema ( definition ) ) . toInclude ( expected )
250253 } )
251254
252255 it ( "returns example value for date property" , function ( ) {
@@ -949,25 +952,62 @@ describe("createXMLExample", function () {
949952 expect ( sut ( definition ) ) . toEqual ( expected )
950953 } )
951954
952- it ( "returns array with example values with wrapped=true" , function ( ) {
953- var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>1</animal>\n\t<animal>2</animal>\n</animals>"
954- var definition = {
955- type : "array" ,
956- items : {
957- type : "string" ,
955+ it ( "returns array with example values with wrapped=true" , function ( ) {
956+ var expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<animals>\n\t<animal>1</animal>\n\t<animal>2</animal>\n</animals>"
957+ var definition = {
958+ type : "array" ,
959+ items : {
960+ type : "string" ,
961+ xml : {
962+ name : "animal"
963+ }
964+ } ,
965+ "example" : [ "1" , "2" ] ,
958966 xml : {
959- name : "animal"
967+ wrapped : true ,
968+ name : "animals"
960969 }
961- } ,
962- "example" : [ "1" , "2" ] ,
963- xml : {
964- wrapped : true ,
965- name : "animals"
966970 }
967- }
968971
969- expect ( sut ( definition ) ) . toEqual ( expected )
970- } )
972+ expect ( sut ( definition ) ) . toEqual ( expected )
973+ } )
974+
975+ it ( "returns array of objects with example values with wrapped=true" , function ( ) {
976+ var expected = `<?xml version="1.0" encoding="UTF-8"?>\n<users>\n\t<user>\n\t\t<id>1</id>\n\t\t<name>Arthur Dent</name>\n\t</user>\n\t<user>\n\t\t<id>2</id>\n\t\t<name>Ford Prefect</name>\n\t</user>\n</users>`
977+ var definition = {
978+ "type" : "array" ,
979+ "items" : {
980+ "type" : "object" ,
981+ "properties" : {
982+ "id" : {
983+ "type" : "integer"
984+ } ,
985+ "name" : {
986+ "type" : "string"
987+ }
988+ } ,
989+ "xml" : {
990+ "name" : "user"
991+ }
992+ } ,
993+ "xml" : {
994+ "name" : "users" ,
995+ "wrapped" : true
996+ } ,
997+ "example" : [
998+ {
999+ "id" : 1 ,
1000+ "name" : "Arthur Dent"
1001+ } ,
1002+ {
1003+ "id" : 2 ,
1004+ "name" : "Ford Prefect"
1005+ }
1006+ ]
1007+ }
1008+
1009+ expect ( sut ( definition ) ) . toEqual ( expected )
1010+ } )
9711011
9721012} )
9731013
0 commit comments