source: trip-planner-front/node_modules/delegates/test/index.js@ b738035

Last change on this file since b738035 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[6a3a178]1
2var assert = require('assert');
3var delegate = require('..');
4
5describe('.method(name)', function(){
6 it('should delegate methods', function(){
7 var obj = {};
8
9 obj.request = {
10 foo: function(bar){
11 assert(this == obj.request);
12 return bar;
13 }
14 };
15
16 delegate(obj, 'request').method('foo');
17
18 obj.foo('something').should.equal('something');
19 })
20})
21
22describe('.getter(name)', function(){
23 it('should delegate getters', function(){
24 var obj = {};
25
26 obj.request = {
27 get type() {
28 return 'text/html';
29 }
30 }
31
32 delegate(obj, 'request').getter('type');
33
34 obj.type.should.equal('text/html');
35 })
36})
37
38describe('.setter(name)', function(){
39 it('should delegate setters', function(){
40 var obj = {};
41
42 obj.request = {
43 get type() {
44 return this._type.toUpperCase();
45 },
46
47 set type(val) {
48 this._type = val;
49 }
50 }
51
52 delegate(obj, 'request').setter('type');
53
54 obj.type = 'hey';
55 obj.request.type.should.equal('HEY');
56 })
57})
58
59describe('.access(name)', function(){
60 it('should delegate getters and setters', function(){
61 var obj = {};
62
63 obj.request = {
64 get type() {
65 return this._type.toUpperCase();
66 },
67
68 set type(val) {
69 this._type = val;
70 }
71 }
72
73 delegate(obj, 'request').access('type');
74
75 obj.type = 'hey';
76 obj.type.should.equal('HEY');
77 })
78})
79
80describe('.fluent(name)', function () {
81 it('should delegate in a fluent fashion', function () {
82 var obj = {
83 settings: {
84 env: 'development'
85 }
86 };
87
88 delegate(obj, 'settings').fluent('env');
89
90 obj.env().should.equal('development');
91 obj.env('production').should.equal(obj);
92 obj.settings.env.should.equal('production');
93 })
94})
Note: See TracBrowser for help on using the repository browser.