javascript - Sinon fakeserver url regexp -


according documentation, sinon fakeserver can use regexp pattern match urls:

server.respondwith(method, urlregexp, response);

i match urls ends foo=1. here attempt:

this.server.respondwith('get', '/foo=1$/', [200,  { 'content-type': 'application/json' }, '{ "foo": 1 }']); 

however, doesn't seem work. regexp wrong, need adjusting it.

http://jsfiddle.net/s38qw3ns/1/

you have single quotes around regular expression, sinon treating string (which :).

get rid of single quotes , regular expression , work expected.

this.server.respondwith('get', /foo=1$/, [200, { 'content-type': 'application/json' }, '{ "foo": 1 }']);

see creating regular expression on mdn reference.


Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -