unjs / rou3

🌳 Lightweight and fast rou(ter) for JavaScript
MIT License
442 stars 16 forks source link

Remove a route with param / wildcard pattern failed #136

Closed a20185 closed 2 weeks ago

a20185 commented 2 weeks ago

Environment

Node

Reproduction

My test cases

  it('should handle wildcard matching removal', () => {
    addRoute(ctx, 'GET', '/user/**:id');
    removeRoute(ctx, 'GET', '/user/**:id');
    expect(findRoute(ctx, 'GET', '/user/123')).toBeUndefined()
    expect(findRoute(ctx, 'GET', '/user/wildcard')).toBeUndefined()
  });

  it('should handle param matching removal', () => {
    addRoute(ctx, 'GET', '/user/:id');
    removeRoute(ctx, 'GET', '/user/:id');
    expect(ctx.root.static).toBeDefined();
    expect(ctx.root.static!['user']).toBeDefined();
    expect(findRoute(ctx, 'GET', '/user/123')).toBeUndefined();
  });

with the output:


  ●  opRemove.removeRoute › should handle wildcard matching removal

    expect(received).toBeUndefined()

    Received: {"data": null, "params": {"id": "123"}}

      34 |     addRoute(ctx, 'GET', '/user/**:id');
      35 |     removeRoute(ctx, 'GET', '/user/**:id');
    > 36 |     expect(findRoute(ctx, 'GET', '/user/123')).toBeUndefined()
         |                                                ^
      37 |     expect(findRoute(ctx, 'GET', '/user/wildcard')).toBeUndefined()
      38 |   });
      39 |

      at Object.<anonymous> (tests/unit/router/operations/remove.spec.ts:36:48)

  ● opRemove.removeRoute › should handle param matching removal

    expect(received).toBeUndefined()

    Received: {"data": null, "params": {"id": "123"}}

      43 |     expect(ctx.root.static).toBeDefined();
      44 |     expect(ctx.root.static!['user']).toBeDefined();
    > 45 |     expect(findRoute(ctx, 'GET', '/user/123')).toBeUndefined();
         |                                                ^
      46 |   });
      47 |
      48 |   it('should handle param matching removal2', () => {

      at Object.<anonymous> (tests/unit/router/operations/remove.spec.ts:45:48)

Describe the bug

Expected the router was being removed. However it does not

Additional context

No response

Logs

No response