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

ember-native-dom-helpers

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

IMPORTANT: You probably don't need this addon.

In Ember, since ember-(cli-)qunit 3.X (around late 2017) there is a new testing API that alreadyprovides almost identical test helpers from the ones in this addon.

This addon was used as an experiment that helped bikeshed the API of the helpers that are now partof default testing API, like click, tap, fillIn and others.

The only two helpers in this addon that are not part of the default set of helpers that ship with Ember'stest harness are scrollTo(selectorOrHTMLElement, x, y) and selectFiles(selectorOrHTMLElement, files = []).

Unless you want to use those, you are better served using the helpers provided by @ember/test-helpers.

ember-native-dom-helpers

Test helpers for integration tests that mimic the behaviour of the acceptancetest helpers provided by Ember.

Use this addon as a way to start the gradual migration towards the future"testing unification" RFC, which proposes only native DOM.

See the Grand Testing Unification RFC

Status: (Pre) 1.0, although we have a good idea about what the needs are fortest helpers, we are working through a few points on what changes are neededwhen using only standard DOM APIs (i.e. without jQuery).

Usage

Integration tests

import { click, fillIn, find, findAll, keyEvent, triggerEvent } from 'ember-native-dom-helpers';

moduleForComponent('my-component', 'Integration | Component | my-component', {
  integration: true
});


test('I can interact with my component', async function(assert) {
  this.render(hbs```
    {{my-component}}
  ```);

  await fillIn('.some-input', 'some text');
  await click('.main-button');
  await keyEvent('.other-input', 'keyup', 40); // down arrow
  await triggerEvent('.some-drop-area', 'mouseenter');

  assert.ok(find('.result-of-event-happened'));
  assert.equal(findAll('.result-list-item').length, 3);
})

Acceptance tests

You can use the exact same helpers for your acceptance tests. All interaction helpers likeclick, fillIn, et al., return a promise that fullfils when "the world has settled"(that is, there are no pending requests or promises, and the runloop has been drained), whichis what the andThen acceptance helper used to do. However, this helper can now be replacedby the async/await syntax in ES2017, yielding easier-to-read tests:

import { visit, click, find, fillIn } from 'ember-native-dom-helpers';

moduleForAcceptance('Acceptance | Sign up');

test('Usage awaiting the world to settle', async function(assert) {
  await visit('/sign-up');

  await fillIn('.first-name', 'Chuck');
  await fillIn('.last-name', 'Berry');
  await click('.submit-btn');

  assert.ok(find('.welcome-msg'), 'There is a welcome banner');
  assert.equal(find('.welcome-msg-name'), 'Chuck');
});

Advantages compared with this.$(selector).click()

The main advantages are:

  • Fires native events: In Ember, when adding events with the onclick={{action "foo"}} syntax,dispatching jQuery events leads to the action being called twice. Additionally, there are subtledifferences between jQuery and Native events that can bite you. Firing native events fixes thatproblem, but they are very verbose and there are browser incompatibilities. This addon makesfiring native events a no-brainer.

  • Runloop aware: These helpers automatically spawn a runloop, so you don't need to wrapevery interaction with Ember.run(() => /* interact with element */ );.

  • wait by default: All the helpers return the wait() promise, making it possible towait for asynchronous side-effects with async/await. (Note that for using async/awaitin browsers without native support you must install ember-maybe-import-regenerator).

    test('some test', async function(assert) {
      this.render(hbs```{{my-component}}```);
    
      await click('.my-button');
    
      assert.ok('something happened');
    });
  • More realistic behaviour: When a user clicks on an element, click is not the only event fired.In a real click, the sequence of events is mousedown, focus, mouseup, click. When a userfills in an input the sequence of events is focus, <mutate-value>, input, and change.The helpers provided by this addon fire those events in the right order, simulating moreclosely how a real user would interact with the page.

Standard DOM elements returned using a find/findAll helpers

  • The find helper uses document.querySelector and will return a single HTMLElement or null.
  • The findAll helper uses document.querySelectorAll and returns an Array with zero or more elements.
  • Both find and findAll helpers query the DOM within #ember-testing.
  • To use a different value from your config/environment.js settings, add to tests/test-helper.js
import { settings } from 'ember-native-dom-helpers';
import config from '../config/environment';
const { APP: { rootElement } } = config;

settings.rootElement = rootElement || settings.rootElement;

What if I prefer jQuery collections over native DOM?

Fear not. If you prefer to use jQuery, just wrap the result and do your thing:

assert.equal($(find('.my-class')).attr('aria-owns'), '#id123')

Testing an unsettled world

There is one new helper in this addon that enables some testing patterns that weren'tpreviously easy to perform using traditional methods.

Since the andThen helper waits for the app to settle (no pending requests or promises),and every integration test interaction is wrapped in Ember.run, there is no easy wayto test transient state, like loading substates or the state of a component, while somepromise is pending, without an awkward setup of timeouts.

Now, however, thanks to explicit usage of promises and the waitUntil helper, you canperform assertions on unsettled states:

import { visit, click, find, fillIn, waitUntil, currentURL } from 'ember-native-dom-helpers';

moduleForAcceptance('Acceptance | Sign up');

test('Usage awaiting the world to settle', async function(assert) {
  await visit('/login');

  await fillIn('.email', '007@gov.uk');
  await fillIn('.password', 'goldeneye');
  let promise = click('.submit-btn');

  // We wait until the loading substate, that takes 200ms to appear, is displayed
  await waitUntil(() => find('.substate-spinner'));
  assert.equal(find('.loading-substate-header').textContent.trim(), 'Loading mission. Please wait, Mr. Bond');

  await promise; // now we wait until the dashboard is fully loaded
  assert.equal(currentURL(), '/dashboard');
  assert.equal(find('.section-header').textContent, 'Main dashboard');
});

I WANT IT NOW, IS THERE A SHORTCUT?

Yes, there is a codemod that will help you transform your test suite to this new style "automatically".Check https://github.com/simonihmig/ember-native-dom-helpers-codemod.

The codemod can't make a perfect conversion, but it will do most of the work for you.

Helpers

  • click(selectorOrHTMLElement, contextHTMLElement, eventOptions)
  • tap(selectorOrHTMLElement, eventOptions)
  • fillIn(selectorOrHTMLElement, text)
  • find(selector, contextHTMLElement) (query for an element in test DOM, #ember-testing)
  • findAll(selector, contextHTMLElement) (query for elements in test DOM, #ember-testing)
  • findWithAssert(selector, contextHTMLElement) (same as find, but raises an Error if no result)
  • keyEvent(selectorOrHTMLElement, type, keyCode, modifiers) (type being keydown, keyup or keypress, modifiers being object with { ctrlKey: false, altKey: false, shiftKey: false, metaKey: false })
  • triggerEvent(selectorOrHTMLElement, type, options)
  • focus(selectorOrHTMLElement)
  • blur(selectorOrHTMLElement)
  • scrollTo(selectorOrHTMLElement, x, y)
  • selectFiles(selectorOrHTMLElement, files = []) (selects the file(s)/Blob(s) to the given input[type=file]. Example
  • visit(url) (only available in acceptance. Raises an error in integration.)
  • waitUntil(function, options) (Polls the page until the given callback returns a truthy value, or timesout after 1s)
  • waitFor(selector, options) (Convenience for the most common use-case of waitUntil. It polls the page until the element with the given selector is on the page, or timesout after 1s. It accepts a count: 3 option to await a specific number of matches.)
  • currentURL() Identical to the one provided by Ember.
  • currentPath() Identical to the one provided by Ember.
  • currentRouteName() Identical to the one provided by Ember.

Notes of tap

In order for tap to work, your browser has to support touch events. Desktop Chrome and Firefoxhave touch events disabled unless the device emulation mode is on. To enable touch events in yourCI, you need to configure testem like the testem.js file on this repo.

  • 在弄react-native的时候,突然发现它不能像js一样获取页面的dom,那如果我要修改一些dom的属性值、文本什么的,要怎么做呢? 后来查谷歌,发现了一个名词:虚拟DOM。 React在内存中维护一个快速响应的DOM描述。render()方法返回一个DOM的描述,React能够利用内存中的描述来快速地计算出差异,然后更新浏览器中的DOM。 为了和浏览器交互,我们需要对DOM节点进行引用,有两

  • this.state:开发中,组件肯定要与用户进行交互,React的一大创新就是将组件看成了一个状态机,一开始有一个初始状态,然后用户交互,导致状态变化,从而触发重新渲染页面 1、当用户点击组件,导致状态变化,this.setSate方法就修改状态值,每次修改以后,会自动调用this.render方法,再次渲染组件 2、可以把组件看成一个状态机,根据不同的status有不同的UI展示,只要使用se

  • 由于之前是做android 原生开发的,最近在学习混合开发,项目中也是用的react native 开发技术,在存储数据时简单点的比如说,用户的登录信息等,都可以存储在 AsyncStorage 中,这个的存储方式为key-value的形式,类似于android 中的SharedPreferences。 后面在存储银行卡信息时,用这个就不是很方便了,就想到了用数据库来存储。 最后就使用了react

  • realm数据库是一款小型数据库系统,可以支持多个平台,如android、ios、javascript等。当然了realm也是可以支持react-native的,官网有具体介绍,官网文档 安装realm npm install --save realm 然后link react-native link realm 或者 rnpm link realm 如果link不完全,可以手动检查添加 1.Ad

  • react native + redux + immutable 举一个加减的小例子 首先,安装依赖: yarn add immutable redux-immutable 使用 redux 时,需要改 reducer: import { combineReducers } from 'redux-immutable' import count from './count' export de

  • 注意:未经允许不可私自转载,违者必究 React Native官方文档:https://reactnative.cn/docs/getting-started/ redux官方文档:https://www.redux.org.cn/ 项目地址GitHub地址:https://github.com/zhouwei1994/nativeCase.git 安装redux react-redux  rea

  • 一、安装mobx yarn add mobx mobx-react babel-preset-mobx 二、开启装饰器 // tsconfig.json文件中 { "compilerOptions":{ ... "experimentalDecorators": true, "emitDecoratorMetadata": true ... } } 三、设置babel //

 相关资料
  • ember-shadow-dom Write templates for your components inside of a Shadow DOM root.Allows encapsulating styles (CSS) and markup (HTML) but using templates likeyou're used to. �� Support for SSR/FastBoot

  • ember-native-class-codemod A codemod for transforming your ember app code to native JavaScript class syntaxwith decorators! Usage First, install the dependencies that the codemod relies on. These area

  • 我正在查看React Native网站,然后我意识到你可以用React Native以及Android/iOS应用构建web应用。我想知道react dom和react Native之间的主要区别是什么,如果这两个库都可以构建web应用程序并操作dom。react-dom有哪些主要特性,react-Native没有?

  • Ember检查器是一个浏览器插件,用于调试Ember应用程序。 灰烬检查员包括以下主题 - S.No. 灰烬检查员方式和描述 1 安装Inspector 您可以安装Ember检查器来调试您的应用程序。 2 Object Inspector Ember检查器允许与Ember对象进行交互。 3 The View Tree 视图树提供应用程序的当前状态。 4 检查路由,数据选项卡和库信息 您可以看到检查

  • 以下指令用于将应用程序数据绑定到HTML DOM元素的属性 - Sr.No. 名称和描述 1 ng-disabled 禁用给定的控件。 2 ng-show 显示给定的控件。 3 ng-hide 隐藏一个给定的控件。 4 ng-click 表示AngularJS单击事件。 ng-disabled Directive 将ng-disabled属性添加到HTML按钮并将其传递给模型。 将模型绑定到复选框

  • 如果要在Oracle中使用特定于数据库的功能(如查询提示或CONNECT关键字),则可以使用本机SQL来表示数据库查询。 Hibernate 3.x允许您为所有创建,更新,删除和加载操作指定手写SQL,包括存储过程。 您的应用程序将使用Session接口上的createSQLQuery()方法从会话创建本机SQL查询 - public SQLQuery createSQLQuery(String