|
| 1 | +return unless NODE_JS |
| 2 | + |
| 3 | +describe 'log', -> |
| 4 | + Given -> @subject = requireSource('log') |
| 5 | + |
| 6 | + describe '.warn', -> |
| 7 | + Given -> @ogWarn = console.warn |
| 8 | + afterEach -> console.warn = @ogWarn |
| 9 | + |
| 10 | + context 'when console.warn is a thing', -> |
| 11 | + Given -> @warnings = [] |
| 12 | + Given -> console.warn = (msg) => @warnings.push(msg) |
| 13 | + |
| 14 | + context 'no URL', -> |
| 15 | + When -> @subject.warn('td.someFunc','ugh') |
| 16 | + Then -> @warnings[0] == 'Warning: testdouble.js - td.someFunc - ugh' |
| 17 | + |
| 18 | + context 'with a documentation URL', -> |
| 19 | + When -> @subject.warn('td.someFunc','ugh', 'http?') |
| 20 | + Then -> @warnings[0] == 'Warning: testdouble.js - td.someFunc - ugh (see: http? )' |
| 21 | + |
| 22 | + context 'with td.config({ignoreWarnings: true})', -> |
| 23 | + Given -> td.config(ignoreWarnings: true) |
| 24 | + When -> @subject.warn('waaaarning') |
| 25 | + Then -> @warnings.length == 0 |
| 26 | + |
| 27 | + context 'when console.warn does not exist', -> |
| 28 | + Given -> console.warn = undefined |
| 29 | + When -> @subject.warn('lolololol', 'lol') |
| 30 | + Then -> #nothing explodes |
| 31 | + |
| 32 | + context 'when console does not exist', -> |
| 33 | + Given -> @ogConsole = console |
| 34 | + Given -> delete global.console |
| 35 | + When -> @subject.warn('lolololol', 'lol') |
| 36 | + Then -> #nothing explodes |
| 37 | + afterEach -> global.console = @ogConsole |
| 38 | + |
| 39 | + describe '.error', -> |
| 40 | + context 'suppressErrors: true', -> |
| 41 | + Given -> td.config(suppressErrors: true) |
| 42 | + When -> @subject.error('hi','hi') |
| 43 | + Then -> # nothing happens |
| 44 | + |
| 45 | + context 'without url', -> |
| 46 | + When -> try |
| 47 | + @subject.error('td.lol', 'oops') |
| 48 | + catch e |
| 49 | + @error = e |
| 50 | + Then -> @error.message = "Error: testdouble.js - td.lol - oops" |
| 51 | + |
| 52 | + context 'with url', -> |
| 53 | + When -> try |
| 54 | + @subject.error('td.lol', 'oops', 'ftp:') |
| 55 | + catch e |
| 56 | + @error = e |
| 57 | + Then -> @error.message = "Error: testdouble.js - td.lol - oops (see: ftp:)" |
| 58 | + |
| 59 | + |
0 commit comments