小编Nic*_*ers的帖子

如何在Angular 2单元测试中触发ngModel模型更新?

我试图测试包含文本输入元素的组件.我想验证当文本输入的值更改时组件的状态按预期更改.当然,文本输入使用ngModel指令(双向绑定).

虽然组件在运行时工作正常,但我在创建有效的传递测试时遇到了麻烦.我发布了我认为应该在下面工作的内容,以及之后的测试结果.

我究竟做错了什么?

测试:

import {Component} from 'angular2/core';
import {describe, it, injectAsync, TestComponentBuilder} from 'angular2/testing';
import {FORM_DIRECTIVES} from 'angular2/common';
import {By} from 'angular2/platform/common_dom';

class TestComponent {
    static get annotations() {
        return [
            new Component({
                template: '<input type="text" [(ngModel)]="name" /><p>Hello {{name}}</p>',
                directives: [FORM_DIRECTIVES]
            })
        ]
    }
}

describe('NgModel', () => {
    it('should update the model', injectAsync([TestComponentBuilder], tcb => {
        return tcb
            .createAsync(TestComponent)
            .then(fixture => {
                fixture.nativeElement.querySelector('input').value = 'John';
                const inputElement = fixture.debugElement.query(By.css('input'));
                inputElement.triggerEventHandler('input', { target: inputElement.nativeElement });
                fixture.detectChanges();
                expect(fixture.componentInstance.name).toEqual('John');
            });
    })); …
Run Code Online (Sandbox Code Playgroud)

unit-testing angular

7
推荐指数
2
解决办法
8555
查看次数

PureScript FFI和Aff Monad:为什么效果永远不会运行?

我是一个纯粹的PureScript新手,需要一些帮助来弄清楚为什么用Aff monad模拟的FFI功能似乎对我不起作用.

预期的行为是在1000ms后将消息"keyMessage"记录到控制台.

相反,程序只是在以下输出后无限期挂起:

Compiling Main
* Build successful.
Waiting for message...
Run Code Online (Sandbox Code Playgroud)

Main.purs:

module Main where

import Prelude
import Control.Monad.Aff (Aff, Fiber, launchAff)
import Control.Monad.Aff.Console (log)
import Control.Monad.Eff (Eff, kind Effect)
import Control.Monad.Eff.Console (CONSOLE)

main :: forall e. Eff (console :: CONSOLE, to :: TIMEOUT | e) (Fiber (console :: CONSOLE, to :: TIMEOUT | e) Unit)
main = launchAff do
  log "Waiting for message..."
  m <- message "key"
  log m

foreign import data TIMEOUT :: Effect

foreign import message …
Run Code Online (Sandbox Code Playgroud)

monads purescript

2
推荐指数
1
解决办法
348
查看次数

标签 统计

angular ×1

monads ×1

purescript ×1

unit-testing ×1