HEX
Server: Apache
System: Linux server.instantlogomakers.com 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: s2spw (1156)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/node_modules/forever/node_modules/director/test/server/core/path-test.js
/*
 * path-test.js: Tests for the core `.path()` method.
 *
 * (C) 2011, Charlie Robbins, Paolo Fragomeni, & the Contributors.
 * MIT LICENSE
 *
 */

var assert = require('assert'),
    vows = require('vows'),
    director = require('../../../lib/director');

vows.describe('director/core/path').addBatch({
  "An instance of director.Router": {
    topic: function () {
      var that = this;
      that.matched = {};
      that.matched['foo'] = [];
      that.matched['newyork'] = [];

      var router = new director.Router({
        '/foo': function () { that.matched['foo'].push('foo'); }
      });
      return router;
    },
    "the path() method": {
      "should create the correct nested routing table": function (router) {
        var that = this;
        router.path('/regions', function () {
          this.on('/:state', function(country) {
            that.matched['newyork'].push('new york');
          });
        });

        assert.isFunction(router.routes.foo.on);
        assert.isObject(router.routes.regions);
        assert.isFunction(router.routes.regions['([._a-zA-Z0-9-%()]+)'].on);
      },
      "should dispatch the function correctly": function (router) {
        router.dispatch('on', '/regions/newyork')
        router.dispatch('on', '/foo');
        assert.equal(this.matched['foo'].length, 1);
        assert.equal(this.matched['newyork'].length, 1);
        assert.equal(this.matched['foo'][0], 'foo');
        assert.equal(this.matched['newyork'][0], 'new york');
      }
    }
  }
}).export(module);