Skip to content

Is there such a thing as an optional param? #11

Description

@mrpickles3rd

Hi. I have been using your URL Assembler for some time but now I need a way to have a param optional. at the moment I only need the last one optional but I have a test for it in the middle of a template. Is there a way I can do this now or would this be a new feature?

If it is a new feature how would I get around the query params messing with ?.

test.js

  describe('given a template with unused params', function () {
    beforeEach(function () {
      myUrl = UrlAssembler('/path/:myparam/:notUsed?/:thisIsUsed');
    });
    describe('.param(key, value)', function () {
      it.only('replaces only the used param in the template', function () {
        expect(myUrl.param({ myparam: 'hello', thisIsUsed: 'YAY'}).toString()).to.equal('/path/hello/YAY');
      })
    });
  });

Terminal Output:

  1) an instance with no baseUrl
       given a template with unused params
         .param(key, value)
           replaces only the used param in the template:

      AssertionError: expected '/path/hello/:notUsed?%2F%3AthisIsUsed=&thisIsUsed=YAY' to equal '/path/hello/YAY'
      + expected - actual

      -/path/hello/:notUsed?%2F%3AthisIsUsed=&thisIsUsed=YAY
      +/path/hello/YAY

      at Context.<anonymous> (test/100-instance.js:122:83)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions