dojo/tests/unit/request/registry.js

Maintainability

78.72

Lines of code

66

Created with Raphaël 2.1.002550751002015-5-18

2015-5-18
Maintainability: 78.72

Created with Raphaël 2.1.0017.53552.5702015-5-18

2015-5-18
Lines of Code: 66

Difficulty

15.21

Estimated Errors

0.46

Function weight

By Complexity

Created with Raphaël 2.1.0<anonymous>2

By SLOC

Created with Raphaël 2.1.0<anonymous>59
1
define([
2
    'intern!object',
3
    'intern/chai!assert',
4
    '../../../request/registry',
5
    'intern/dojo/has',
6
    'intern/dojo/_base/lang',
7
    'intern/dojo/has!host-browser?dojo/domReady!'
8
], function (registerSuite, assert, registry, has, lang) {
9
 
10
    var suite = {
11
        name: 'dojo/request/registry',
12
        '.register': {
13
            'RegExp registration works': function () {
14
                var dfd = this.async();
15
                var handle = registry.register(/^foo/, dfd.callback(function (url) {
16
                    assert.match(url, /^foo/);
17
                    handle.remove();
18
                }));
19
 
20
                registry.get('foobar');
21
            },
22
 
23
            'functional registration works': function () {
24
                var dfd = this.async();
25
                var handle = registry.register(function (url, options) {
26
                    return options.method === 'POST';
27
                }, dfd.callback(function (url, options) {
28
                    assert.equal(options.method, 'POST');
29
                    handle.remove();
30
                }));
31
 
32
                registry.post('foobar');
33
            },
34
 
35
            'string registration works': function () {
36
                var dfd = this.async();
37
                var handle = registry.register('foobar', dfd.callback(function (url) {
38
                    assert.equal(url, 'foobar');
39
                    handle.remove();
40
                }));
41
 
42
                registry.get('foobar');
43
            }
44
        }
45
    };
46
 
47
    if(has('host-browser')) {
48
        suite['.get'] = {
49
            'fallback works': function () {
50
                var dfd = this.async();
51
                var url = 'client.html';
52
                var handle = registry.register('foobar', function () {
53
                });
54
 
55
                registry.get(url)
56
                    .then(lang.hitch(dfd, dfd.resolve), lang.hitch(dfd, dfd.reject))
57
                    .always(function () {
58
                        handle.remove();
59
                    }
60
                );
61
            }
62
        };
63
    }
64
 
65
    registerSuite(suite);
66
});