Skip to content
Myr

spec.utils.js

This file

Path

spec/spec.utils.js

138 lines · 3.9 KiB · JavaScript

Last changed by

Merge branch 'upload'visionmediabefore adoption5495fbc

History of this file

Take it

Mergevisionmediabefore adoptioncec6770

lines 1–70why, one step back
1
2describe 'Express'3 before4 utils = require('express/utils')5 end6 7 describe 'toArray()'8 describe 'when given an array'9 it 'should return the array'10 utils.toArray([1,2,3]).should.eql [1,2,3]11 end12 end13 14 describe 'when given an object with indexed values and length'15 it 'should return an array'16 var args = -{ return arguments }('foo', 'bar')17 utils.toArray(args).should.eql ['foo', 'bar']18 end19 end20 end21 22 describe 'escape()'23 it 'should escape html'24 utils.escape('<p>this & that').should.eql '&lt;p&gt;this &amp; that'25 end26 end27 28 describe 'uid()'29 it 'should return a string of random characters'30 utils.uid().should.not.eql utils.uid()31 utils.uid().length.should.be_greater_than 2032 end33 end34 35 describe 'extname()'36 it 'should return the a files extension'37 utils.extname('image.png').should.eql 'png'38 utils.extname('image.large.png').should.eql 'png'39 utils.extname('/path/to/image.large.png').should.eql 'png'40 end41 42 it 'should return null when not found'43 utils.extname('path').should.be_null44 utils.extname('/just/a/path').should.be_null45 end46 end47 48 describe 'basename()'49 it 'should return a files basename'50 utils.basename('foo/bar/baz.image.png').should.eql 'baz.image.png'51 end52 end53 54 describe 'mergeParam()'55 describe 'with empty params'56 it 'should merge the given key and value'57 params = {}58 utils.mergeParam('user[names][first]', 'tj', params)59 params.user.names.first.should.eql 'tj'60 end61 end62 63 describe 'with populated params'64 it 'should merge not overwrite'65 params = { user: { name: 'tj' }}66 utils.mergeParam('user[email]', 'tj@vision-media.ca', params)67 params.user.name.should.eql 'tj'68 params.user.email.should.eql 'tj@vision-media.ca'69 end70 end

Merge branch 'upload'visionmediabefore adoption5495fbc

lines 71–136why, one step back
71
72 describe 'with an object as value'73 it 'should preserve it'74 params = {}75 utils.mergeParam('images[]', { name: 1 }, params)76 utils.mergeParam('images[]', { name: 2 }, params)77 params.images.should.eql [{ name: 1}, { name: 2 }]78 end79 end80 81 describe 'key[number]'82 it 'should merge correctly'83 params = { images: { one: 'foo.png' }}84 utils.mergeParam('images[0]', 'bar.png', params)85 params.images.one.should.eql 'foo.png'86 params.images[0].should.eql 'bar.png'87 end88 end89 90 describe 'key[]'91 describe 'with a single value'92 it 'should still be an array'93 params = {}94 utils.mergeParam('images[]', '1', params)95 params.images.should.eql ['1']96 end97 end98 99 describe 'with empty params'100 it 'should merge correctly'101 params = {}102 utils.mergeParam('images[]', '1', params)103 utils.mergeParam('images[]', '2', params)104 params.images.should.eql ['1', '2']105 end106 end107 108 describe 'with populated params'109 it 'should convert to an array'110 params = { images: 'foo.png'}111 utils.mergeParam('images[]', '1', params)112 params.images.should.eql ['foo.png', '1']113 end114 end115 116 describe 'with several merges'117 it 'should push values'118 params = {}119 utils.mergeParam('images[]', '1', params)120 utils.mergeParam('images[]', '2', params)121 utils.mergeParam('images[]', '3', params)122 params.images.should.eql ['1', '2', '3']123 end124 end125 126 describe 'when nested'127 it 'should marge correctly'128 params = {}129 utils.mergeParam('user[tj][images][]', '1', params)130 utils.mergeParam('user[tj][images][]', '2', params)131 utils.mergeParam('user[tj][images][]', '3', params)132 params.user.should.eql { tj: { images: ['1', '2', '3'] }}133 end134 end135 end136

Mergevisionmediabefore adoptioncec6770

lines 137–138why, one step back
137 end
138end