Enabling better element selectors in Ember.js tests
Removes attributes starting with data-test-
from HTML tags andcomponent/helper invocations in your templates for production builds
Removes properties starting with data-test-
from your JS objects likecomponent classes for production builds
More information on why that is useful are available on ourblog!
ember install ember-test-selectors
In your templates you are now able to use data-test-*
attributes, which areautomatically removed from production
builds:
Once you've done that you can use attribute selectors to look up and interactwith those elements:
assert.dom('[data-test-post-title]').hasText('Ember is great!');
await click('[data-test-like-button]');
You can use the same syntax also for component invocations:
Inside the Spinner
component template the data-test-spinner
attribute willbe applied to the element that has ...attributes
on it, or on the componentwrapper div
element if you don't use tagName = ''
.
If you want to use ember-test-selectors in an addon make sure that it appearsin the dependencies
section of the package.json
file, not in thedevDependencies
. This ensures that the selectors are also stripped correctlyeven if the app that uses the addon does not use ember-test-selectors itself.
You can override when the data-test-*
attributes should be stripped from thebuild by modifying your ember-cli-build.js
file:
var app = new EmberApp({
'ember-test-selectors': {
strip: false
}
});
strip
accepts a Boolean
value and defaults to !app.tests
, which meansthat the attributes will be stripped for production builds, unless the buildwas triggered by ember test
. That means that if you useember test --environment=production
the test selectors will still work, butfor ember build -prod
they will be stripped out.
ember-test-selectors is developed by and ©simplabs GmbH and contributors. It is released under theMIT License.
ember-test-selectors is not an official part of Ember.jsand is not maintained by the Ember.js Core Team.
test() 方法 用于检测一个字符串是否匹配某个模式。 语法: RegExpObject.test( string ) 参数说明: string - 要检索的字符串 返回值: 如果字符串 string 中含有与 RegExpObject 匹配的文本,则返回 true,否则返回 false。 说明: 调用 RegExp 对象 r 的 test() 方法,并为它传递字符串 s,与这个表示式是等
用于测试的一些脚本。
描述 (Description) test方法在字符串中搜索与regexp匹配的文本。 如果找到匹配,则返回true; 否则,它返回false。 语法 (Syntax) 其语法如下 - RegExpObject.test( string ); 参数细节 (Parameter Details) string - 要搜索的字符串 返回值 (Return Value) 如果找到匹配则返回匹配的文本,否
Ember检查器是一个浏览器插件,用于调试Ember应用程序。 灰烬检查员包括以下主题 - S.No. 灰烬检查员方式和描述 1 安装Inspector 您可以安装Ember检查器来调试您的应用程序。 2 Object Inspector Ember检查器允许与Ember对象进行交互。 3 The View Tree 视图树提供应用程序的当前状态。 4 检查路由,数据选项卡和库信息 您可以看到检查
写书时,有时需要一些自动化测试.例如,The Rust Programming Book使用了许多可能过时的代码示例。因此,能够自动测试这些代码示例对他们来说非常重要. mdBook 支持test将运行,书中所有可用测试的命令。目前,只支持 rustdoc 测试,但未来可能会扩展. rustdoc 不会测试,包含ignore属性的代码块: ```rust,ignore fn main() {} `
See rationale for motivating scenarios. Post-MVP, applications will be able to query which features are supported via has_feature or a similar API. This accounts for the pragmatic reality that feature