|
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import expectDeprecation from 'ember-qunit/assertions/expect-deprecation'; |
| 3 | +import { deprecate } from '@ember/debug'; |
| 4 | + |
| 5 | +// ............................................................ |
| 6 | +// Deprecation outside of a test. Should not cause test failures. |
| 7 | +deprecate('Deprecation outside of a test', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 8 | +// ............................................................ |
| 9 | + |
| 10 | +module('expectDeprecation', function(hooks) { |
| 11 | + let mockAssert; |
| 12 | + |
| 13 | + hooks.beforeEach(() => { |
| 14 | + mockAssert = { |
| 15 | + pushedResults: [], |
| 16 | + expectDeprecation, |
| 17 | + }; |
| 18 | + }); |
| 19 | + |
| 20 | + test('expectDeprecation called after test and with deprecation', function(assert) { |
| 21 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 22 | + |
| 23 | + mockAssert.expectDeprecation(); |
| 24 | + |
| 25 | + assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` captured deprecation call'); |
| 26 | + }); |
| 27 | + |
| 28 | + test('expectDeprecation called after test and without deprecation', function(assert) { |
| 29 | + mockAssert.expectDeprecation(); |
| 30 | + assert.notOk(mockAssert.pushedResults[0].result, '`expectDeprecation` logged failed result'); |
| 31 | + }); |
| 32 | + |
| 33 | + test('expectDeprecation called with callback and with deprecation', function(assert) { |
| 34 | + mockAssert.expectDeprecation(() => { |
| 35 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 36 | + }); |
| 37 | + |
| 38 | + assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` captured deprecation call'); |
| 39 | + }); |
| 40 | + |
| 41 | + test('expectDeprecation called with callback and without deprecation', function(assert) { |
| 42 | + mockAssert.expectDeprecation(() => { }); |
| 43 | + assert.notOk(mockAssert.pushedResults[0].result, '`expectDeprecation` logged failed result'); |
| 44 | + }); |
| 45 | + |
| 46 | + test('expectDeprecation called with callback and after test', function(assert) { |
| 47 | + mockAssert.expectDeprecation(() => { |
| 48 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 49 | + }); |
| 50 | + |
| 51 | + mockAssert.expectDeprecation(); |
| 52 | + assert.ok(mockAssert.pushedResults[0].result, 'first `expectDeprecation` captured deprecation call'); |
| 53 | + assert.notOk(mockAssert.pushedResults[1].result, 'second `expectDeprecation` logged failed result'); |
| 54 | + }); |
| 55 | + |
| 56 | + test('expectDeprecation called after test, with matcher and matched deprecation', function(assert) { |
| 57 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 58 | + |
| 59 | + mockAssert.expectDeprecation(/Something deprecated/); |
| 60 | + assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` captured deprecation call'); |
| 61 | + }); |
| 62 | + |
| 63 | + test('expectDeprecation called after test, with matcher and unmatched deprecation', function(assert) { |
| 64 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 65 | + |
| 66 | + mockAssert.expectDeprecation(/different deprecation/); |
| 67 | + assert.notOk(mockAssert.pushedResults[0].result, '`expectDeprecation` logged failed result'); |
| 68 | + }); |
| 69 | + |
| 70 | + test('expectDeprecation called with callback, matcher and matched deprecation', function(assert) { |
| 71 | + mockAssert.expectDeprecation(() => { |
| 72 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 73 | + }, /Something deprecated/); |
| 74 | + |
| 75 | + assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` captured deprecation call'); |
| 76 | + }); |
| 77 | + |
| 78 | + test('expectDeprecation called with callback, matcher and unmatched deprecation', function(assert) { |
| 79 | + mockAssert.expectDeprecation(() => { |
| 80 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 81 | + }, /different deprecation/); |
| 82 | + |
| 83 | + assert.notOk(mockAssert.pushedResults[0].result, '`expectDeprecation` logged failed result'); |
| 84 | + }); |
| 85 | + |
| 86 | + test('expectNoDeprecation called after test and without deprecation', function(assert) { |
| 87 | + assert.expectNoDeprecation(); |
| 88 | + assert.ok(mockAssert.pushedResults[0].result, '`expectNoDeprecation` caught no deprecation'); |
| 89 | + }); |
| 90 | + |
| 91 | + test('expectNoDeprecation called after test and with deprecation', function(assert) { |
| 92 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 93 | + |
| 94 | + assert.expectNoDeprecation(); |
| 95 | + assert.notOk(mockAssert.pushedResults[0].result, '`expectNoDeprecation` caught logged failed result'); |
| 96 | + }); |
| 97 | + |
| 98 | + test('expectNoDeprecation called with callback and with deprecation', function(assert) { |
| 99 | + assert.expectNoDeprecation(() => { |
| 100 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 101 | + }); |
| 102 | + |
| 103 | + assert.notOk(mockAssert.pushedResults[0].result, '`expectNoDeprecation` caught logged failed result'); |
| 104 | + }); |
| 105 | + |
| 106 | + test('expectNoDeprecation called with callback and without deprecation', function(assert) { |
| 107 | + assert.expectNoDeprecation(() => { }); |
| 108 | + assert.ok(mockAssert.pushedResults[0].result, '`expectNoDeprecation` caught no deprecation'); |
| 109 | + }); |
| 110 | + |
| 111 | + test('expectNoDeprecation called with callback and after test', function(assert) { |
| 112 | + assert.expectNoDeprecation(() => { |
| 113 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 114 | + }); |
| 115 | + |
| 116 | + assert.expectNoDeprecation(); |
| 117 | + assert.notOk(mockAssert.pushedResults[0].result, 'first `expectNoDeprecation` caught logged failed result'); |
| 118 | + assert.ok(mockAssert.pushedResults[1].result, 'second `expectNoDeprecation` caught no deprecation'); |
| 119 | + }); |
| 120 | + |
| 121 | + test('expectDeprecation with regex matcher', function(assert) { |
| 122 | + mockAssert.expectDeprecation(() => { |
| 123 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 124 | + }, /Somethi[a-z ]*ecated/); |
| 125 | + mockAssert.expectDeprecation(() => { |
| 126 | + deprecate('/Something* deprecated/', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 127 | + }, /Something* deprecated/); |
| 128 | + |
| 129 | + assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` matched RegExp'); |
| 130 | + assert.notOk(mockAssert.pushedResults[1].result, '`expectDeprecation` didn\'t RegExp as String match'); |
| 131 | + }); |
| 132 | + |
| 133 | + test('expectDeprecation with string matcher', function(assert) { |
| 134 | + mockAssert.expectDeprecation(() => { |
| 135 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 136 | + }, 'Something'); |
| 137 | + |
| 138 | + mockAssert.expectDeprecation(() => { |
| 139 | + deprecate('Something deprecated', false, { id: 'deprecation-test', until: '3.0.0' }); |
| 140 | + }, 'Something.*'); |
| 141 | + |
| 142 | + assert.ok(mockAssert.pushedResults[0].result, '`expectDeprecation` captured deprecation for partial String match'); |
| 143 | + assert.notOk(mockAssert.pushedResults[1].result, '`expectDeprecation` didn\'t test a String match as RegExp'); |
| 144 | + }); |
| 145 | +}); |
0 commit comments