Skip to content
Myr

spec.utils.js

This file

Path

spec/spec.utils.js

104 lines · 2.9 KiB · JavaScript

Last changed by

Removed extname() / basename() utils. Using path modulevisionmediabefore adoption962f5fa

History of this file

Take it

Mergevisionmediabefore adoptioncec6770

lines 1–23why, one step back
1
2describe 'Express'3 before4 utils = require('express/utils')5 end6 7 describe 'escape()'8 it 'should escape html'9 utils.escape('<p>this & that').should.eql '&lt;p&gt;this &amp; that'10 end11 end12 13 describe 'uid()'14 it 'should return a string of random characters'15 utils.uid().should.not.eql utils.uid()16 utils.uid().length.should.be_greater_than 2017 end18 end19 20 describe 'mergeParam()'21 describe 'with empty params'22 it 'should merge the given key and value'23 params = {}

Merge branch 'ext'visionmediabefore adoption364c131

lines 24–25why, one step back
24 utils.mergeParam('user[names][firstName]', 'tj', params)
25 params.user.names.firstName.should.eql 'tj'

Mergevisionmediabefore adoptioncec6770

lines 26–36why, one step back
26 end
27 end28 29 describe 'with populated params'30 it 'should merge not overwrite'31 params = { user: { name: 'tj' }}32 utils.mergeParam('user[email]', 'tj@vision-media.ca', params)33 params.user.name.should.eql 'tj'34 params.user.email.should.eql 'tj@vision-media.ca'35 end36 end

Merge branch 'upload'visionmediabefore adoption5495fbc

lines 37–102why, one step back
37
38 describe 'with an object as value'39 it 'should preserve it'40 params = {}41 utils.mergeParam('images[]', { name: 1 }, params)42 utils.mergeParam('images[]', { name: 2 }, params)43 params.images.should.eql [{ name: 1}, { name: 2 }]44 end45 end46 47 describe 'key[number]'48 it 'should merge correctly'49 params = { images: { one: 'foo.png' }}50 utils.mergeParam('images[0]', 'bar.png', params)51 params.images.one.should.eql 'foo.png'52 params.images[0].should.eql 'bar.png'53 end54 end55 56 describe 'key[]'57 describe 'with a single value'58 it 'should still be an array'59 params = {}60 utils.mergeParam('images[]', '1', params)61 params.images.should.eql ['1']62 end63 end64 65 describe 'with empty params'66 it 'should merge correctly'67 params = {}68 utils.mergeParam('images[]', '1', params)69 utils.mergeParam('images[]', '2', params)70 params.images.should.eql ['1', '2']71 end72 end73 74 describe 'with populated params'75 it 'should convert to an array'76 params = { images: 'foo.png'}77 utils.mergeParam('images[]', '1', params)78 params.images.should.eql ['foo.png', '1']79 end80 end81 82 describe 'with several merges'83 it 'should push values'84 params = {}85 utils.mergeParam('images[]', '1', params)86 utils.mergeParam('images[]', '2', params)87 utils.mergeParam('images[]', '3', params)88 params.images.should.eql ['1', '2', '3']89 end90 end91 92 describe 'when nested'93 it 'should marge correctly'94 params = {}95 utils.mergeParam('user[tj][images][]', '1', params)96 utils.mergeParam('user[tj][images][]', '2', params)97 utils.mergeParam('user[tj][images][]', '3', params)98 params.user.should.eql { tj: { images: ['1', '2', '3'] }}99 end100 end101 end102

Mergevisionmediabefore adoptioncec6770

lines 103–104why, one step back
103 end
104end