当前位置: 首页 > 软件库 > 程序开发 > >

ember-test-selectors

授权协议 MIT License
开发语言 JavaScript
所属分类 程序开发
软件类型 开源软件
地区 不详
投 递 者 栾鸣
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

ember-test-selectors

Enabling better element selectors in Ember.js tests

Features

  • 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!

Compatibility

  • Ember 3.8 or above
  • Ember CLI 3.8 or above
  • Node.js 12 or above

Installation

ember install ember-test-selectors

Usage

In your templates you are now able to use data-test-* attributes, which areautomatically removed from production builds:

<article>
  <h1 data-test-post-title data-test-resource-id={{post.id}}>{{post.title}}</h1>
  <p>{{post.body}}</p>
  <button data-test-like-button>Like</button>
</article>

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]');

Usage with Components

You can use the same syntax also for component invocations:

<Spinner @color="blue" data-test-spinner>

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 = ''.

Usage in Ember addons

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.

Configuration

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.

License

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) 如果找到匹配则返回匹配的文本,否

  • 写书时,有时需要一些自动化测试.例如,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

  • Runs the test script defined by the package. yarn test If you have defined a scripts object in your package, this command will run the specified test script. For example, if you have a bash script in