ok, fai così

val = 'test test test';
val = val.replace(/\s+/g, "+");