Skip to content
Myr

Added utils.accepts(type, str)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent 376a5da · Browse files · 2 files+121 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+121 added−0 removed

  • tests:+79 added−0 removed
  • other:+42 added−0 removed

2 files+121 added−0 removed

modified:lib/utils.js+42 added
modified:test/utils.js+79 added
74 unmodified lines
75 it('should provide .subtype', function(){76 var arr = utils.parseAccept('text/html');77 arr[0].subtype.should.equal('html');78 })79})8081describe('utils.accepts(type, str)', function(){82 describe('when a string is not given', function(){83 it('should return true', function(){84 utils.accepts('text/html')85 .should.be.true;86 })87 })88 89 describe('when a string is empty', function(){90 it('should return true', function(){91 utils.accepts('text/html', '')92 .should.be.true;93 })94 })95 96 describe('when */* is given', function(){97 it('should return true', function(){98 utils.accepts('text/html', 'text/plain, */*')99 .should.be.true;100 })101 })102103 describe('when accepting type/subtype', function(){104 it('should return true when present', function(){105 utils.accepts('text/html', 'text/plain, text/html')106 .should.be.true;107 })108 109 it('should return false otherwise', function(){110 utils.accepts('text/html', 'text/plain, application/json')111 .should.be.false;112 })113 })114 115 describe('when accepting */subtype', function(){116 it('should return true when present', function(){117 utils.accepts('text/html', 'text/*')118 .should.be.true;119 })120 121 it('should return false otherwise', function(){122 utils.accepts('text/html', 'image/*')123 .should.be.false;124 })125 })126 127 describe('when accepting type/*', function(){128 it('should return true when present', function(){129 utils.accepts('text/html', '*/html')130 .should.be.true;131 })132 133 it('should return false otherwise', function(){134 utils.accepts('text/html', '*/json')135 .should.be.false;136 })137 })138 139 describe('when an extension is given', function(){140 it('should return true when present', function(){141 utils.accepts('html', 'text/html, application/json')142 .should.be.true;143 })144 145 it('should return false otherwise', function(){146 utils.accepts('html', 'text/plain, application/json')147 .should.be.false;148 })149 150 it('should support *', function(){151 utils.accepts('html', 'text/*')152 .should.be.true;153154 utils.accepts('html', '*/html')155 .should.be.true;156 })157 })158})