我正在写一个Ember.js插件,我需要弃用一个特性。我可以使用和Ember相同的弃用系统吗?我希望我的用户能够使警告静默。
理想情况下,我还需要能够在我的测试套件中测试弃用消息是否在正确的条件下工作。
我使用的是Ember 3.x。
发布于 2019-06-06 06:50:54
通过deprecate
方法,插件可以使用与Ember相同的弃用警告样式:
import { deprecate } from '@ember/application/deprecations';
deprecate
有三个参数:作为消息的字符串、布尔测试( falsey表示将显示弃用信息)和一个包含更多信息的options对象。
例如:
import { deprecate } from '@ember/application/deprecations';
// ...
deprecate(
"message about your addon that mentions the addon by name",
false,
{
id: 'send-component-hash',
until: '2.0.0',
url: 'some url goes here'
}
);
// ...
控制台中的消息将如下所示:
可以使用像ember-qunit-assert这样的库来测试弃用。安装完成后,如果您已经在测试中使用了expectDeprecation
,则可以在assert
上使用qunit
:
assert.expectDeprecation(/expected deprecation message/);
https://stackoverflow.com/questions/56469007
复制相似问题